Example #1
0
    def _test_ok(self, admission_api, clean_migrated_db, auth=None):
        identity = json.dumps({"mac": "new-preauth-mac"})

        _, pub = get_keypair()
        admission_api.preauthorize(identity, pub, auth)

        asets = admission_api.get_devices(auth=auth)
        assert len(asets) == 1
        assert asets[0].status == 'preauthorized'
Example #2
0
    def _test_bad_key(self, admission_api, clean_migrated_db, auth=None):
        identity = json.dumps({"mac": "new-preauth-mac"})

        try:
            admission_api.preauthorize(identity, 'invalid', auth)
        except bravado.exception.HTTPError as e:
            assert e.response.status_code == 400
            assert e.response.swagger_result.error == 'cannot decode public key'

        asets = admission_api.get_devices(auth=auth)
        assert len(asets) == 0
Example #3
0
    def _test_conflict(self, admission_api, devices, auth=None):
        _, pub = get_keypair()
        for dev, _ in devices:
            try:
                identity = dev.identity
                admission_api.preauthorize(identity, pub, auth)
            except bravado.exception.HTTPError as e:
                assert e.response.status_code == 409

        asets = admission_api.get_devices(auth=auth)
        assert len(asets) == len(devices)
Example #4
0
    def _test_bad_req_iddata(self,
                             admission_api,
                             clean_migrated_db,
                             auth=None):
        _, pub = get_keypair()
        try:
            admission_api.preauthorize('not-valid-json', pub, auth)
        except bravado.exception.HTTPError as e:
            assert e.response.status_code == 400

        asets = admission_api.get_devices(auth=auth)
        assert len(asets) == 0
Example #5
0
    def _test_id_data_formatting(self,
                                 admission_api,
                                 clean_migrated_db,
                                 auth=None):
        _, pub = get_keypair()

        iddata = [
            "{\"mac\": \"mac1\", \"sn\": \"sn1\"}",
            "{\"sn\": \"sn1\", \"mac\": \"mac1\"}",
            "{\"mac\":\"mac1\",\"sn\": \"sn1\"}",
            "{\"sn\":\"sn1\",\"mac\":\"mac1\"}",
        ]

        res = admission_api.preauthorize(iddata[0], pub, auth)

        for i in iddata[1:]:
            try:
                admission_api.preauthorize(i, pub, auth)
            except bravado.exception.HTTPError as e:
                assert e.response.status_code == 409
                assert e.response.swagger_result.error == 'device already exists'

        asets = admission_api.get_devices(auth=auth)
        assert len(asets) == 1