def test_ok(self, clean_mongo):
        uuidv4 = str(uuid.uuid4())
        name = "test.mender.io-" + uuidv4
        email = "user@{}.com".format(name)
        res = create_org_v1(name, email, "asdfqwer1234", "tok_visa")

        # wait for create org workflow
        utok = try_login(api_uadm, email, "asdfqwer1234")

        # what's the tenant id?
        res = api_tadm_v1.with_auth(utok).call(
            "GET", tenantadm_v1.URL_MGMT_THIS_TENANT)
        assert res.status_code == 200

        tid = res.json()["id"]

        res = api_tadm_v2.with_auth(utok).call("POST",
                                               tenantadm_v2.URL_TENANT_SECRET)
        assert res.status_code == 200
        secret = res.json()["secret"]

        # UI uses the secret to collect card and confirm the setup intent
        # let's use a different card
        seti = stripeutils.find_setup_intent(secret)
        stripeutils.confirm("pm_card_mastercard", seti["id"])

        res = api_tadm_v2.call(
            "PUT",
            tenantadm_v2.URL_TENANT_STATUS,
            path_params={"id": tid},
            body={"status": "active"},
        )
        assert res.status_code == 202

        # verify the old source is detached and new one attached
        cust = stripeutils.customer_for_tenant(email)

        assert cust["default_source"] is None
        assert len(cust["sources"]) == 0

        stripeutils.customer_has_pm(cust)

        # cleanup
        # setup intents can't be cleaned up apparently, cancel doesn't work
        stripeutils.delete_cust(cust["id"])
Exemple #2
0
    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)
Exemple #3
0
 def _cleanup_stripe(self, tenant_email):
     cust = stripeutils.customer_for_tenant(tenant_email)
     stripeutils.delete_cust(cust["id"])
    def test_ok_non_sca_cards(self, clean_mongo, card):
        """ Basic test card numbers.

        These cards won't trigger extra auth flows, but still have to work with the SCA-ready workflow.
        They are actually the only cards we can use to test the whole flow on the backend side.

        See https://stripe.com/docs/testing#cards.

        Some of these are omitted - they are in fact being rejected with:
        'Please use a Visa, MasterCard, or American Express card'
        """
        uuidv4 = str(uuid.uuid4())
        tenant = "test.mender.io-" + uuidv4
        uname, upass = "******".format(tenant), "asdfqwer1234"
        payload = {
            "request_id": "123456",
            "organization": tenant,
            "email": uname,
            "password": upass,
            "g-recaptcha-response": "foobar",
        }

        res = api_tadm_v2.call(
            "POST",
            tenantadm_v2.URL_CREATE_ORG_TENANT,
            headers={"Content-Type": "application/x-www-form-urlencoded"},
            data=payload,
        )
        assert res.status_code == 200

        secret = res.json()["secret"]
        assert len(secret) > 0
        tid = res.json()["id"]

        # user can't log in until the org is activated
        r = api_uadm.call("POST", useradm.URL_LOGIN, auth=(uname, upass))
        assert r.status_code == 401

        # we're emulating CC collection (and setup intent confirmation)
        # setup intent cofirm is the last step normally done by the stripe ui components
        seti = stripeutils.find_setup_intent(secret)

        stripeutils.confirm(card, seti["id"])

        # tenant can be activated now
        res = api_tadm_v2.call(
            "PUT",
            tenantadm_v2.URL_TENANT_STATUS,
            path_params={"id": tid},
            body={"status": "active"},
        )
        assert res.status_code == 202

        # wait for create org workflow, try login
        try_login(api_uadm, uname, upass)

        # verify that tenant's customer has an attached
        # payment method/default payment method
        cust = stripeutils.customer_for_tenant(uname)
        stripeutils.customer_has_pm(cust)

        # cleanup
        # setup intents can't be cleaned up apparently, cancel doesn't work
        stripeutils.delete_cust(cust["id"])
Exemple #5
0
    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)