def test_token_validator_gets_token_from_auth_code(rf, django_user_model): """ We should get our tokens back with a user. """ c = Config() req = rf.get("/") add_session(req) with patch( "okta_oauth2.tokens.TokenValidator.call_token_endpoint", get_token_result ), patch("okta_oauth2.tokens.TokenValidator._jwks", Mock(return_value="secret")): tv = TokenValidator(c, "defaultnonce", req) user, tokens = tv.tokens_from_auth_code("authcode") assert "access_token" in tokens assert "id_token" in tokens assert isinstance(user, django_user_model)
def test_user_username_setting_returns_user_by_username_and_not_email( rf, settings, django_user_model ): settings.OKTA_AUTH = update_okta_settings(settings.OKTA_AUTH, "USE_USERNAME", True) c = Config() req = rf.get("/") add_session(req) with patch( "okta_oauth2.tokens.TokenValidator.call_token_endpoint", get_token_result ), patch("okta_oauth2.tokens.TokenValidator._jwks", Mock(return_value="secret")): tv = TokenValidator(c, "defaultnonce", req) user, tokens = tv.tokens_from_auth_code("authcode") assert isinstance(user, django_user_model) assert user.username == "fakemail" assert user.username != "*****@*****.**"