Ejemplo n.º 1
0
 def test_ok_no_db(self, cli, clean_db, mongo):
     cli.migrate()
     TestMigration.verify(cli, mongo, DB_NAME, DB_VERSION)
Ejemplo n.º 2
0
 def test_ok_stale_db(self, cli, fake_migrated_db, mongo):
     cli.migrate()
     TestMigration.verify(cli, mongo, DB_NAME, DB_VERSION)
Ejemplo n.º 3
0
    def test_migrate(self, cli, clean_db, mongo):
        cli.migrate()

        TestMigration.verify_db_and_collections(mongo, DB_NAME)
        TestMigration.verify_migration(mongo[DB_NAME], DB_VERSION)
Ejemplo n.º 4
0
    def test_migrate(self, cli, clean_db, mongo):
        cli.migrate(tenant_id="foobar")

        tenant_db = DB_NAME + '-foobar'
        TestMigration.verify_db_and_collections(mongo, tenant_db)
        TestMigration.verify_migration(mongo[tenant_db], DB_VERSION)
Ejemplo n.º 5
0
    def test_migrate(self, cli, clean_db_f, mongo):
        cli.migrate(tenant_id="0000000000000000000000")

        tenant_db = Migration.DB_NAME + "-0000000000000000000000"
        Migration.verify_db_and_collections(mongo, tenant_db)
        Migration.verify_migration(mongo[tenant_db], Migration.DB_VERSION)
Ejemplo n.º 6
0
def accepted_tenants_devices(device_api, management_api, clean_migrated_db,
                             cli, request):
    """Fixture that sets up an accepted devices for tenants. The fixture can
       be parametrized with a tenants, number of devices and number of authentication sets.
       Yields a dict:
       [tenant ID: [device object, ...], ]"""

    requested = request.param

    tenants_devices = dict()
    url = device_api.auth_requests_url

    for (tenant, dev_count, auth_count) in requested:

        tenant_devices = []
        cli.migrate(tenant=tenant)
        tenant_token = make_fake_tenant_token(tenant)
        for _ in range(int(dev_count)):
            d = Device()
            for i in range(int(auth_count)):
                d.rotate_key()
                da = DevAuthorizer(tenant_token=tenant_token)

                # poke devauth so that device appears
                handlers = [
                    ('POST', '/api/internal/v1/tenantadm/tenants/verify',
                     lambda _: (200, {}, {
                         'id': '507f191e810c19729de860ea',
                         'name': 'Acme',
                     })),
                ]
                with mockserver.run_fake(get_fake_tenantadm_addr(),
                                         handlers=handlers) as fake:
                    with deviceadm.run_fake_for_device(d) as fakedevadm:
                        rsp = device_auth_req(url, da, d)
                        assert rsp.status_code == 401

                # try to find our devices in all devices listing
                dev = management_api.find_device_by_identity(
                    d.identity, Authorization='Bearer ' + tenant_token)

                devid = dev.id
                for a in dev.auth_sets:
                    if compare_keys(a.pubkey, d.public_key):
                        aid = a.id
                        break

                try:
                    with orchestrator.run_fake_for_device_id(devid) as server:
                        management_api.accept_device(devid,
                                                     aid,
                                                     Authorization='Bearer ' +
                                                     tenant_token)
                except bravado.exception.HTTPError as e:
                    assert e.response.status_code == 204

                token = request_token(d, da, device_api.auth_requests_url)
                assert len(token) > 0

            assert dev
            tenant_devices.append(d)

        tenants_devices[tenant] = tenant_devices
    yield tenants_devices
Ejemplo n.º 7
0
    def test_migrate(self, cli, clean_db_f, mongo):
        cli.migrate()

        Migration.verify_db_and_collections(mongo, Migration.DB_NAME)
        Migration.verify_migration(mongo[Migration.DB_NAME],
                                   Migration.DB_VERSION)
Ejemplo n.º 8
0
 def test_ok_future_db(self, cli, fake_migrated_db, mongo):
     cli.migrate()
     TestMigration.verify(cli, mongo, DB_NAME, "2.0.0")
Ejemplo n.º 9
0
 def test_ok_future_db(self, cli, fake_migrated_db, mongo):
     code, _, _ = cli.migrate()
     assert code == 0
     TestMigration.verify(cli, mongo, DB_NAME, "2.0.0")
Ejemplo n.º 10
0
 def test_ok_current_db(self, cli, fake_migrated_db, mongo):
     code, _, _ = cli.migrate()
     assert code == 0
     TestMigration.verify(cli, mongo, DB_NAME, DB_VERSION)
Ejemplo n.º 11
0
 def test_ok_no_db(self, cli, clean_db, mongo):
     code, _, _ = cli.migrate()
     assert code == 0
     TestMigration.verify(cli, mongo, DB_NAME, DB_VERSION)