def test_duplicate_email(self, clean_migrated_mongo): tc = ApiClient(tenantadm.URL_MGMT, host=tenantadm.HOST, schema="http://") uuidv4 = str(uuid.uuid4()) tenant = "test.mender.io-" + uuidv4 email = "some.user@{}.com".format(tenant) payload = { "request_id": "123456", "organization": tenant, "email": email, "password": "******", "g-recaptcha-response": "foobar", "token": "tok_visa", } rsp = tc.post(tenantadm.URL_MGMT_TENANTS, data=payload) assert rsp.status_code == 202 uuidv4 = str(uuid.uuid4()) tenant = "test.mender.io-" + uuidv4 payload = { "request_id": "123457", "organization": tenant, "email": email, "password": "******", "g-recaptcha-response": "foobar", "token": "tok_visa", } rsp = tc.post(tenantadm.URL_MGMT_TENANTS, data=payload) assert rsp.status_code == 409 self._cleanup_stripe(email)
def test_duplicate_email(self, clean_migrated_mongo): tc = ApiClient(tenantadm.URL_MGMT) tenant = "tenant{}".format(randstr()) email = "some.user@{}.com".format(tenant) payload = { "request_id": "123456", "organization": tenant, "email": email, "password": "******", "g-recaptcha-response": "foobar", "token": "tok_visa", } rsp = tc.post(tenantadm.URL_MGMT_TENANTS, data=payload) assert rsp.status_code == 202 tenant = "tenant{}".format(randstr()) payload = { "request_id": "123457", "organization": tenant, "email": email, "password": "******", "g-recaptcha-response": "foobar", "token": "tok_visa", } rsp = tc.post(tenantadm.URL_MGMT_TENANTS, data=payload) assert rsp.status_code == 409 self._cleanup_stripe(email)
def test_success_with_plan(self, clean_migrated_mongo): tc = ApiClient(tenantadm.URL_MGMT) uc = ApiClient(useradm.URL_MGMT) tenantadmi = ApiClient(tenantadm.URL_INTERNAL) devauthi = ApiClient(deviceauth_v1.URL_INTERNAL) logging.info("Starting TestCreateOrganizationEnterprise") tenant = "tenant{}".format(randstr()) email = "some.user@{}.com".format(tenant) payload = { "request_id": "123456", "organization": tenant, "email": email, "password": "******", "g-recaptcha-response": "foobar", "plan": "professional", "token": "tok_visa", } r = tc.post(tenantadm.URL_MGMT_TENANTS, data=payload) assert r.status_code == 202 # Try log in every second for 5 minutes. # Creating organization is an async job # and may take some time to complete. for i in range(5 * 60): rsp = uc.call( "POST", useradm.URL_LOGIN, auth=(email, "asdfqwer1234"), ) if rsp.status_code == 200: break time.sleep(1) if rsp.status_code != 200: raise ValueError( "User could not log in within five minutes after organization has been created." ) # get the tenant id (and verify that only one tenant exists) r = tenantadmi.call("GET", tenantadm.URL_INTERNAL_TENANTS) assert r.status_code == 200 api_tenants = r.json() assert len(api_tenants) == 1 # verify the device limit via internal api # the device limit for professional plan should be 250 r = devauthi.call( "GET", deviceauth_v1.URL_LIMITS_MAX_DEVICES, path_params={"tid": api_tenants[0]["id"]}, ) assert r.status_code == 200 assert r.json()["limit"] == 250 self._cleanup_stripe(email)
def test_duplicate_organization_name(self, clean_migrated_mongo): tc = ApiClient(tenantadm.URL_MGMT) payload = { "request_id": "123456", "organization": "tenant-foo", "email": "*****@*****.**", "password": "******", "g-recaptcha-response": "foobar", } rsp = tc.post(tenantadm.URL_MGMT_TENANTS, data=payload) assert rsp.status_code == 202 payload = { "request_id": "123457", "organization": "tenant-foo", "email": "*****@*****.**", "password": "******", "g-recaptcha-response": "foobar", } rsp = tc.post(tenantadm.URL_MGMT_TENANTS, data=payload) assert rsp.status_code == 202
def test_success(self, clean_migrated_mongo): tc = ApiClient(tenantadm.URL_MGMT) uc = ApiClient(useradm.URL_MGMT) logging.info("Starting TestCreateOrganizationEnterprise") smtp_mock = SMTPMock() thread = Thread(target=smtp_mock.start) thread.daemon = True thread.start() payload = { "request_id": "123456", "organization": "tenant-foo", "email": "*****@*****.**", "password": "******", "g-recaptcha-response": "foobar", } r = tc.post(tenantadm.URL_MGMT_TENANTS, data=payload) assert r.status_code == 202 for i in range(60 * 5): if len(smtp_mock.filtered_messages) > 0: break time.sleep(1) logging.info( "TestCreateOrganizationEnterprise: Waiting finished. Stoping mock") smtp_mock.stop() logging.info("TestCreateOrganizationEnterprise: Mock stopped.") smtp_mock.assert_called() logging.info("TestCreateOrganizationEnterprise: Assert ok.") # Try log in every second for 3 minutes. # - There usually is a slight delay (in order of ms) for propagating # the created user to the db. for i in range(3 * 60): rsp = uc.call( "POST", useradm.URL_LOGIN, auth=("*****@*****.**", "asdfqwer1234"), ) if rsp.status_code == 200: break time.sleep(1) if rsp.status_code != 200: raise ValueError( "User could not log in within three minutes after organization has been created." )
def test_plan_invalid(self, clean_migrated_mongo): tc = ApiClient(tenantadm.URL_MGMT, host=tenantadm.HOST, schema="http://") payload = { "request_id": "123456", "organization": "tenant-foo", "email": "*****@*****.**", "password": "******", "g-recaptcha-response": "foobar", "plan": "foo", "token": "tok_visa", } rsp = tc.post(tenantadm.URL_MGMT_TENANTS, data=payload) assert rsp.status_code == 400
def test_success(self, clean_migrated_mongo): tc = ApiClient(tenantadm.URL_MGMT, host=tenantadm.HOST, schema="http://") uc = ApiClient(useradm.URL_MGMT) tenantadmi = ApiClient(tenantadm.URL_INTERNAL, host=tenantadm.HOST, schema="http://") devauthi = ApiClient(deviceauth_v1.URL_INTERNAL, host=deviceauth_v1.HOST, schema="http://") logging.info("Starting TestCreateOrganizationEnterprise") uuidv4 = str(uuid.uuid4()) tenant = "test.mender.io-" + uuidv4 email = "some.user@{}.com".format(tenant) payload = { "request_id": "123456", "organization": tenant, "email": email, "password": "******", "g-recaptcha-response": "foobar", "token": "tok_visa", } r = tc.post(tenantadm.URL_MGMT_TENANTS, data=payload) assert r.status_code == 202 # Try log in every second for 3 minutes. # - There usually is a slight delay (in order of ms) for propagating # the created user to the db. for i in range(3 * 60): rsp = uc.call( "POST", useradm.URL_LOGIN, auth=(email, "asdfqwer1234"), ) if rsp.status_code == 200: break time.sleep(1) if rsp.status_code != 200: raise ValueError( "User could not log in within three minutes after organization has been created." ) # get the tenant id (and verify that only one tenant exists) qs = parse.urlencode({"q": tenant}) r = tenantadmi.call("GET", tenantadm.URL_INTERNAL_TENANTS + "?" + qs) assert r.status_code == 200 api_tenants = r.json() assert len(api_tenants) == 1 # verify the device limit via internal api # the default plan is "os" so the device limit should be set to 50 r = devauthi.call( "GET", deviceauth_v1.URL_INTERNAL_LIMITS_MAX_DEVICES, path_params={"tid": api_tenants[0]["id"]}, ) assert r.status_code == 200 assert r.json()["limit"] == 50 # verify there is a stripe customer with a correctly assigned source cust = stripeutils.customer_for_tenant(email) assert cust.default_source is not None assert len(cust.sources) == 1 self._cleanup_stripe(email)
def test_success(self, clean_migrated_mongo): tc = ApiClient(tenantadm.URL_MGMT) uc = ApiClient(useradm.URL_MGMT) tenantadmi = ApiClient(tenantadm.URL_INTERNAL) devauthi = ApiClient(deviceauth_v1.URL_INTERNAL) logging.info("Starting TestCreateOrganizationEnterprise") smtp_mock = SMTPMock() thread = Thread(target=smtp_mock.start) thread.daemon = True thread.start() tenant = "tenant{}".format(randstr()) email = "some.user@{}.com".format(tenant) payload = { "request_id": "123456", "organization": tenant, "email": email, "password": "******", "g-recaptcha-response": "foobar", "token": "tok_visa", } r = tc.post(tenantadm.URL_MGMT_TENANTS, data=payload) assert r.status_code == 202 for i in range(60 * 5): if len(smtp_mock.filtered_messages(email)) > 0: break time.sleep(1) logging.info( "TestCreateOrganizationEnterprise: Waiting finished. Stoping mock") smtp_mock.stop() logging.info("TestCreateOrganizationEnterprise: Mock stopped.") smtp_mock.assert_called(email) logging.info("TestCreateOrganizationEnterprise: Assert ok.") # Try log in every second for 3 minutes. # - There usually is a slight delay (in order of ms) for propagating # the created user to the db. for i in range(3 * 60): rsp = uc.call( "POST", useradm.URL_LOGIN, auth=(email, "asdfqwer1234"), ) if rsp.status_code == 200: break time.sleep(1) if rsp.status_code != 200: raise ValueError( "User could not log in within three minutes after organization has been created." ) # get the tenant id (and verify that only one tenant exists) r = tenantadmi.call("GET", tenantadm.URL_INTERNAL_TENANTS) assert r.status_code == 200 api_tenants = r.json() assert len(api_tenants) == 1 # verify the device limit via internal api # the default plan is "os" so the device limit should be set to 50 r = devauthi.call( "GET", deviceauth_v1.URL_LIMITS_MAX_DEVICES, path_params={"tid": api_tenants[0]["id"]}, ) assert r.status_code == 200 assert r.json()["limit"] == 50 # verify there is a stripe customer with a correctly assigned source cust = stripeutils.customer_for_tenant(email) assert cust.default_source is not None assert len(cust.sources) == 1 self._cleanup_stripe(email)