~dbarth/click-apparmor/clean-trust-dbs

« back to all changes in this revision

Viewing changes to test-clicktool.py

  • Committer: Jamie Strandboge
  • Date: 2015-04-15 21:32:33 UTC
  • Revision ID: jamie@ubuntu.com-20150415213233-o1ogn2hujc3asz50
Tags: 0.3.7
* add find_usable_framework() and use it to parse lists in the frameworks
  field of the snappy compat click manifest. This is needed for snaps to use
  snap frameworks

Show diffs side-by-side

added added

removed removed

Lines of Context:
1295
1295
                          "Expected to get %s, got %s" %
1296
1296
                          (expected, easyprof_manifest))
1297
1297
 
 
1298
    def test_parse_security_manifest_framework_core_1504_list(self):
 
1299
        '''Test manifest framework (core 15.04) - list'''
 
1300
        c = self.clickstate
 
1301
        package = "com.ubuntu.developer.username.yourapp"
 
1302
        c.add_package(package, "0.3", framework='nonexist,ubuntu-core-15.04')
 
1303
        security_json = '''{
 
1304
  "policy_vendor": "ubuntu-core",
 
1305
  "template": "service",
 
1306
  "policy_groups": [ "networking" ],
 
1307
  "policy_version": 15.04
 
1308
}'''
 
1309
        appname = 'sample-app'
 
1310
        c.add_app(appname, manifest=security_json)
 
1311
 
 
1312
        cm = click.ClickManifest(os.path.join(c.click_dir,
 
1313
                                 "%s_%s_0.3.json" % (package, appname)))
 
1314
        easyprof_manifest = click.transform(cm)
 
1315
 
 
1316
        dbus_id = click.dbus_path("%s_%s_0.3" % (package, appname))
 
1317
        dbus_pkgname = click.dbus_path(c.package)
 
1318
 
 
1319
        expected = json.loads('''{
 
1320
  "profiles": {
 
1321
    "%s_%s_0.3": {
 
1322
      "policy_groups": [
 
1323
        "networking"
 
1324
      ],
 
1325
      "policy_vendor": "ubuntu-core",
 
1326
      "policy_version": 15.04,
 
1327
      "template": "service",
 
1328
      "template_variables": {
 
1329
        "APP_ID_DBUS": "%s",
 
1330
        "APP_PKGNAME_DBUS": "%s",
 
1331
        "APP_PKGNAME": "%s",
 
1332
        "APP_APPNAME": "%s",
 
1333
        "APP_VERSION": "0.3",
 
1334
        "CLICK_DIR": "%s"
 
1335
      }
 
1336
    }
 
1337
  }
 
1338
}''' % (package, appname, dbus_id, dbus_pkgname, package, appname,
 
1339
            click_databases))
 
1340
        self.assertEquals(expected, easyprof_manifest,
 
1341
                          "Expected to get %s, got %s" %
 
1342
                          (expected, easyprof_manifest))
 
1343
 
 
1344
    def test_parse_security_manifest_framework_core_1504_list2(self):
 
1345
        '''Test manifest framework (core 15.04) - list altered order'''
 
1346
        c = self.clickstate
 
1347
        package = "com.ubuntu.developer.username.yourapp"
 
1348
        c.add_package(package, "0.3", framework='ubuntu-core-15.04,nonexist')
 
1349
        security_json = '''{
 
1350
  "policy_vendor": "ubuntu-core",
 
1351
  "template": "service",
 
1352
  "policy_groups": [ "networking" ],
 
1353
  "policy_version": 15.04
 
1354
}'''
 
1355
        appname = 'sample-app'
 
1356
        c.add_app(appname, manifest=security_json)
 
1357
 
 
1358
        cm = click.ClickManifest(os.path.join(c.click_dir,
 
1359
                                 "%s_%s_0.3.json" % (package, appname)))
 
1360
        easyprof_manifest = click.transform(cm)
 
1361
 
 
1362
        dbus_id = click.dbus_path("%s_%s_0.3" % (package, appname))
 
1363
        dbus_pkgname = click.dbus_path(c.package)
 
1364
 
 
1365
        expected = json.loads('''{
 
1366
  "profiles": {
 
1367
    "%s_%s_0.3": {
 
1368
      "policy_groups": [
 
1369
        "networking"
 
1370
      ],
 
1371
      "policy_vendor": "ubuntu-core",
 
1372
      "policy_version": 15.04,
 
1373
      "template": "service",
 
1374
      "template_variables": {
 
1375
        "APP_ID_DBUS": "%s",
 
1376
        "APP_PKGNAME_DBUS": "%s",
 
1377
        "APP_PKGNAME": "%s",
 
1378
        "APP_APPNAME": "%s",
 
1379
        "APP_VERSION": "0.3",
 
1380
        "CLICK_DIR": "%s"
 
1381
      }
 
1382
    }
 
1383
  }
 
1384
}''' % (package, appname, dbus_id, dbus_pkgname, package, appname,
 
1385
            click_databases))
 
1386
        self.assertEquals(expected, easyprof_manifest,
 
1387
                          "Expected to get %s, got %s" %
 
1388
                          (expected, easyprof_manifest))
 
1389
 
1298
1390
    def test_parse_security_manifest_framework_core_1504_subframework(self):
1299
1391
        '''Test manifest framework 15.04 core (subframeworks)'''
1300
1392
        for sub in ['-dev', '-dev1']:
1405
1497
                                     "%s_sample-app_0.3.json" % pkg))
1406
1498
            click.transform(cm)
1407
1499
        except click.AppArmorExceptionClickFrameworkNotFound as e:
1408
 
            self.assertTrue("Unknown framework" in str(e))
 
1500
            self.assertTrue("Could not find usable framework in" in str(e))
1409
1501
            return
1410
1502
        except Exception:
1411
1503
            raise