def _test_get_devices(self, init_authsets, api_client_mgmt, auth=None):
        # get all authsets
        authsets = api_client_mgmt.get_devices(auth=auth)
        assert len(authsets) == len(init_authsets)

        # check authsets by status, verify for each known status
        for status in ['accepted', 'rejected', 'pending', 'preauthorized']:
            init_with_status = [
                a for a in init_authsets if a['status'] == status
            ]
            current_with_status = api_client_mgmt.get_devices(status=status,
                                                              auth=auth)

            assert len(init_with_status) == len(current_with_status)
    def _test_ok_nonexistent(self, api_client_mgmt, init_authsets, auth=None):
        id = "nonexistent"

        rsp = api_client_mgmt.delete_device_mgmt(id, auth)
        assert rsp.status_code == 204

        devs = api_client_mgmt.get_devices(auth=auth)
        assert len(devs) == len(init_authsets)
Beispiel #3
0
    def _test_bad_req_iddata(self, api_client_mgmt, init_authsets, auth=None):
        try:
            api_client_mgmt.preauthorize('not-valid-json', 'new-preauth-key',
                                         auth)
        except bravado.exception.HTTPError as e:
            assert e.response.status_code == 400

        asets = api_client_mgmt.get_devices(auth=auth)
        assert len(asets) == len(init_authsets)
Beispiel #4
0
    def _test_conflict(self, api_client_mgmt, init_authsets, auth=None):
        for aset in init_authsets:
            try:
                identity = aset.device_identity
                api_client_mgmt.preauthorize(identity, 'new-preauth-key', auth)
            except bravado.exception.HTTPError as e:
                assert e.response.status_code == 409

        asets = api_client_mgmt.get_devices(auth=auth)
        assert len(asets) == len(init_authsets)
    def _test_ok(self, api_client_mgmt, init_authsets, auth=None):
        id = init_authsets[0].id
        device_id = init_authsets[0].device_id

        with deviceauth.run_fake_delete_device(device_id, id, 204):
            rsp = api_client_mgmt.delete_device_mgmt(id, auth)
            assert rsp.status_code == 204

        devs = api_client_mgmt.get_devices(auth=auth)
        assert len(devs) == len(init_authsets) - 1

        deleted = [a for a in devs if a.id == id]
        assert len(deleted) == 0
Beispiel #6
0
    def _test_ok(self, api_client_mgmt, init_authsets, auth=None):
        identity = json.dumps({"mac": "new-preauth-mac"})

        with deviceauth.run_fake_preauth(identity, 'new-preauth-key', 201):
            api_client_mgmt.preauthorize(identity, 'new-preauth-key', auth)

        asets = api_client_mgmt.get_devices(auth=auth)
        assert len(asets) == len(init_authsets) + 1

        preauth = [
            a for a in asets
            if a.status == 'preauthorized' and a.device_identity == identity
        ]
        assert len(preauth) == 1
    def _do_test_ok(self,
                    api_client_int,
                    api_client_mgmt,
                    init_authsets,
                    auth=None):
        """
            Tests the happy path.
        """

        # find the preauthorized device and accept
        preauth = [d for d in init_authsets if d.status == 'preauthorized']
        assert len(preauth) == 1
        preauth = preauth[0]

        api_client_int.change_status(preauth.id, 'accepted', auth)

        # assert that the preauth device is now accepted
        devs = api_client_mgmt.get_devices(auth=auth)
        accepted = [
            d for d in devs if d.id == preauth.id and d.status == 'accepted'
        ]
        assert len(accepted) == 1