Example #1
0
    def test_raises_when_malformed_client_id(self, basic_auth_creds,
                                             pyramid_request, valid_payload):
        basic_auth_creds.return_value = ('foobar', 'somerandomsecret')
        pyramid_request.json_body = valid_payload

        with pytest.raises(ClientUnauthorized):
            create(pyramid_request)
Example #2
0
    def test_raises_for_public_client(self, factories, basic_auth_creds,
                                      pyramid_request, valid_payload):
        auth_client = factories.AuthClient(authority='weylandindustries.com')
        basic_auth_creds.return_value = (auth_client.id, '')
        pyramid_request.json_body = valid_payload

        with pytest.raises(ClientUnauthorized):
            create(pyramid_request)
Example #3
0
    def test_it_validates_the_input(self, pyramid_request, valid_payload, schemas):
        create_schema = schemas.CreateUserAPISchema.return_value
        create_schema.validate.return_value = valid_payload
        pyramid_request.json_body = valid_payload

        create(pyramid_request)

        create_schema.validate.assert_called_once_with(valid_payload)
Example #4
0
    def test_raises_when_client_secret_invalid(self, auth_client,
                                               basic_auth_creds,
                                               pyramid_request, valid_payload):
        basic_auth_creds.return_value = (auth_client.id, 'incorrectsecret')
        pyramid_request.json_body = valid_payload

        with pytest.raises(ClientUnauthorized):
            create(pyramid_request)
Example #5
0
    def test_it_validates_the_input(self, pyramid_request, valid_payload, schemas):
        create_schema = schemas.CreateUserAPISchema.return_value
        create_schema.validate.return_value = valid_payload
        pyramid_request.json_body = valid_payload

        create(pyramid_request)

        create_schema.validate.assert_called_once_with(valid_payload)
Example #6
0
    def test_raises_when_no_client(self, basic_auth_creds, pyramid_request,
                                   valid_payload):
        basic_auth_creds.return_value = (
            'C69BA868-5089-4EE4-ABB6-63A1C38C395B', 'somerandomsecret')
        pyramid_request.json_body = valid_payload

        with pytest.raises(ClientUnauthorized):
            create(pyramid_request)
Example #7
0
    def test_raises_when_schema_validation_fails(self, pyramid_request, valid_payload, schemas):
        create_schema = schemas.CreateUserAPISchema.return_value
        create_schema.validate.side_effect = ValidationError('validation failed')

        pyramid_request.json_body = valid_payload

        with pytest.raises(ValidationError):
            create(pyramid_request)
Example #8
0
    def test_raises_when_schema_validation_fails(self, pyramid_request, valid_payload, schemas):
        create_schema = schemas.CreateUserAPISchema.return_value
        create_schema.validate.side_effect = ValidationError('validation failed')

        pyramid_request.json_body = valid_payload

        with pytest.raises(ValidationError):
            create(pyramid_request)
Example #9
0
    def test_raises_when_authority_doesnt_match(self, pyramid_request, valid_payload, auth_client):
        payload = valid_payload
        payload['authority'] = 'foo-%s' % auth_client.authority
        pyramid_request.json_body = payload

        with pytest.raises(ValidationError) as exc:
            create(pyramid_request)

        assert "'authority' does not match authenticated client" in str(exc.value)
Example #10
0
    def test_raises_when_malformed_client_id(self,
                                             basic_auth_creds,
                                             pyramid_request,
                                             valid_payload):
        basic_auth_creds.return_value = ('foobar', 'somerandomsecret')
        pyramid_request.json_body = valid_payload

        with pytest.raises(ClientUnauthorized):
            create(pyramid_request)
Example #11
0
    def test_raises_when_authority_doesnt_match(self, pyramid_request, valid_payload, auth_client):
        payload = valid_payload
        payload['authority'] = 'foo-%s' % auth_client.authority
        pyramid_request.json_body = payload

        with pytest.raises(ValidationError) as exc:
            create(pyramid_request)

        assert "'authority' does not match authenticated client" in str(exc.value)
Example #12
0
    def test_raises_when_client_secret_invalid(self,
                                               auth_client,
                                               basic_auth_creds,
                                               pyramid_request,
                                               valid_payload):
        basic_auth_creds.return_value = (auth_client.id, 'incorrectsecret')
        pyramid_request.json_body = valid_payload

        with pytest.raises(ClientUnauthorized):
            create(pyramid_request)
Example #13
0
    def test_raises_when_no_client(self,
                                   basic_auth_creds,
                                   pyramid_request,
                                   valid_payload):
        basic_auth_creds.return_value = ('C69BA868-5089-4EE4-ABB6-63A1C38C395B',
                                         'somerandomsecret')
        pyramid_request.json_body = valid_payload

        with pytest.raises(ClientUnauthorized):
            create(pyramid_request)
Example #14
0
    def test_raises_for_invalid_client_grant_type(self, factories,
                                                  basic_auth_creds,
                                                  pyramid_request,
                                                  valid_payload):
        auth_client = factories.ConfidentialAuthClient(
            authority='weylandindustries.com',
            grant_type=GrantType.authorization_code)
        basic_auth_creds.return_value = (auth_client.id, auth_client.secret)
        pyramid_request.json_body = valid_payload

        with pytest.raises(ClientUnauthorized):
            create(pyramid_request)
Example #15
0
    def test_signs_up_user(self, factories, pyramid_request,
                           user_signup_service, valid_payload):
        pyramid_request.json_body = valid_payload
        user_signup_service.signup.return_value = factories.User.build(
            **valid_payload)

        create(pyramid_request)

        user_signup_service.signup.assert_called_once_with(
            require_activation=False,
            authority='weylandindustries.com',
            username='******',
            email='*****@*****.**')
Example #16
0
    def test_raises_when_email_taken(self, pyramid_request, valid_payload,
                                     db_session, factories, auth_client):
        existing_user = factories.User(authority=auth_client.authority)
        db_session.flush()

        payload = valid_payload
        payload['email'] = existing_user.email
        pyramid_request.json_body = payload

        with pytest.raises(ValidationError) as exc:
            create(pyramid_request)

        assert ('email address %s already exists' %
                existing_user.email) in str(exc.value)
Example #17
0
    def test_signs_up_user(self,
                           factories,
                           pyramid_request,
                           user_signup_service,
                           valid_payload):
        pyramid_request.json_body = valid_payload
        user_signup_service.signup.return_value = factories.User.build(**valid_payload)

        create(pyramid_request)

        user_signup_service.signup.assert_called_once_with(
            require_activation=False,
            authority='weylandindustries.com',
            username='******',
            email='*****@*****.**')
Example #18
0
    def test_raises_when_email_taken(self,
                                     pyramid_request,
                                     valid_payload,
                                     db_session,
                                     factories,
                                     auth_client):
        existing_user = factories.User(authority=auth_client.authority)
        db_session.flush()

        payload = valid_payload
        payload['email'] = existing_user.email
        pyramid_request.json_body = payload

        with pytest.raises(ValidationError) as exc:
            create(pyramid_request)

        assert ('email address %s already exists' % existing_user.email) in str(exc.value)
Example #19
0
    def test_returns_user_object(self, factories, pyramid_request,
                                 user_signup_service, valid_payload):
        pyramid_request.json_body = valid_payload
        user_signup_service.signup.return_value = factories.User.build(
            **valid_payload)

        result = create(pyramid_request)

        assert result == {
            'userid': 'acct:[email protected]',
            'username': '******',
            'email': '*****@*****.**',
            'authority': 'weylandindustries.com',
        }
Example #20
0
    def test_returns_user_object(self,
                                 factories,
                                 pyramid_request,
                                 user_signup_service,
                                 valid_payload):
        pyramid_request.json_body = valid_payload
        user_signup_service.signup.return_value = factories.User.build(**valid_payload)

        result = create(pyramid_request)

        assert result == {
            'userid': 'acct:[email protected]',
            'username': '******',
            'email': '*****@*****.**',
            'authority': 'weylandindustries.com',
        }
Example #21
0
    def test_raises_when_no_creds(self, pyramid_request, valid_payload):
        pyramid_request.json_body = valid_payload

        with pytest.raises(ClientUnauthorized):
            create(pyramid_request)
Example #22
0
    def test_raises_when_no_creds(self, pyramid_request, valid_payload):
        pyramid_request.json_body = valid_payload

        with pytest.raises(ClientUnauthorized):
            create(pyramid_request)