def do_test_put_status_failed(self, devs_authsets, user): useradmm = ApiClient(useradm.URL_MGMT) devauthm = ApiClient(deviceauth_v2.URL_MGMT) r = useradmm.call("POST", useradm.URL_LOGIN, auth=(user.name, user.pwd)) assert r.status_code == 200 utoken = r.text # not found: valid device, bogus authset r = devauthm.with_auth(utoken).call( "PUT", deviceauth_v2.URL_AUTHSET_STATUS, deviceauth_v2.req_status("accepted"), path_params={"did": devs_authsets[0].id, "aid": "foo"}, ) assert r.status_code == 404 # not found: bogus device r = devauthm.with_auth(utoken).call( "PUT", deviceauth_v2.URL_AUTHSET_STATUS, deviceauth_v2.req_status("accepted"), path_params={"did": "foo", "aid": "bar"}, ) assert r.status_code == 404 # bad request - invalid status r = devauthm.with_auth(utoken).call( "PUT", deviceauth_v2.URL_AUTHSET_STATUS, deviceauth_v2.req_status("invalid"), path_params={ "did": devs_authsets[0].id, "aid": devs_authsets[0].authsets[0].id, }, ) assert r.status_code == 400 # bad request - invalid payload r = devauthm.with_auth(utoken).call( "PUT", deviceauth_v2.URL_AUTHSET_STATUS, '{"foo": "bar"}', path_params={ "did": devs_authsets[0].id, "aid": devs_authsets[0].authsets[0].id, }, ) assert r.status_code == 400
def change_authset_status(dauthm, did, aid, status, utoken): r = dauthm.with_auth(utoken).call( "PUT", deviceauth_v2.URL_AUTHSET_STATUS, deviceauth_v2.req_status(status), path_params={"did": did, "aid": aid}, ) assert r.status_code == 204
def change_authset_status(dauthm, did, aid, status, utoken): r = dauthm.with_auth(utoken).call('PUT', deviceauth_v2.URL_AUTHSET_STATUS, deviceauth_v2.req_status(status), path_params={ 'did': did, 'aid': aid }) assert r.status_code == 204
def test_limits_max_devices(self, tenants_devs_authsets): devauthi = ApiClient(deviceauth_v1.URL_INTERNAL) devauthm = ApiClient(deviceauth_v2.URL_MGMT) devauthd = ApiClient(deviceauth_v1.URL_DEVICES) useradmm = ApiClient(useradm.URL_MGMT) for t in tenants_devs_authsets: # get num currently accepted devices num_acc = len(filter_and_page_devs(t.devices, status="accepted")) # set limit to that r = devauthi.call( "PUT", deviceauth_v1.URL_LIMITS_MAX_DEVICES, {"limit": num_acc}, path_params={"tid": t.id}, ) assert r.status_code == 204 # get limit via internal api r = devauthi.call( "GET", deviceauth_v1.URL_LIMITS_MAX_DEVICES, path_params={"tid": t.id} ) assert r.status_code == 200 assert r.json()["limit"] == num_acc # get limit via mgmt api r = useradmm.call( "POST", useradm.URL_LOGIN, auth=(t.users[0].name, t.users[0].pwd) ) assert r.status_code == 200 utoken = r.text r = devauthm.with_auth(utoken).call( "GET", deviceauth_v2.URL_LIMITS_MAX_DEVICES ) assert r.status_code == 200 assert r.json()["limit"] == num_acc # try accept a device manually pending = filter_and_page_devs(t.devices, status="pending")[0] r = devauthm.with_auth(utoken).call( "PUT", deviceauth_v2.URL_AUTHSET_STATUS, deviceauth_v2.req_status("accepted"), path_params={"did": pending.id, "aid": pending.authsets[0].id}, ) assert r.status_code == 422 # try exceed the limit via preauth'd device preauthd = filter_and_page_devs(t.devices, status="preauthorized")[0] body, sighdr = deviceauth_v1.auth_req( preauthd.id_data, preauthd.authsets[0].pubkey, preauthd.authsets[0].privkey, t.tenant_token, ) r = devauthd.call("POST", deviceauth_v1.URL_AUTH_REQS, body, headers=sighdr) assert r.status_code == 401