diff --git a/swh/auth/pytest_plugin.py b/swh/auth/pytest_plugin.py --- a/swh/auth/pytest_plugin.py +++ b/swh/auth/pytest_plugin.py @@ -97,6 +97,10 @@ options["verify_exp"] = False options["verify_aud"] = False decoded = super().decode_token(token, options) + # Merge the user info configured to be part of the decode token + userinfo = self.userinfo() + if userinfo is not None: + decoded = {**decoded, **userinfo} # tweak auth and exp time for tests expire_in = decoded["exp"] - decoded["auth_time"] if self.exp is not None: diff --git a/swh/auth/tests/sample_data.py b/swh/auth/tests/sample_data.py --- a/swh/auth/tests/sample_data.py +++ b/swh/auth/tests/sample_data.py @@ -7,6 +7,18 @@ REALM_NAME = "SoftwareHeritage" CLIENT_ID = "client-id" +USER_INFO = { + "email": "john.doe@example.com", + "email_verified": False, + "family_name": "Doe", + "given_name": "John", + "groups": [], + "name": "John Doe", + "preferred_username": "johndoe", + "sub": "feacd344-b468-4a65-a236-14f61e6b7200", +} + + # Decoded token (out of the access token) DECODED_TOKEN = { "jti": "31fc50b7-bbe5-4f51-91ef-8e3eec51331e", @@ -15,7 +27,6 @@ "iat": 1582723101, "iss": "http://localhost:8080/auth/realms/SoftwareHeritage", "aud": [CLIENT_ID, "account"], - "sub": "feacd344-b468-4a65-a236-14f61e6b7200", "typ": "Bearer", "azp": CLIENT_ID, "auth_time": 1614786418, @@ -27,13 +38,7 @@ "account": {"roles": ["manage-account", "manage-account-links", "view-profile"]} }, "scope": "openid email profile", - "email_verified": False, - "name": "John Doe", - "groups": [], - "preferred_username": "johndoe", - "given_name": "John", - "family_name": "Doe", - "email": "john.doe@example.com", + **USER_INFO, } # Authentication response is an oidc profile dict @@ -113,17 +118,6 @@ "token_type": "bearer", } -USER_INFO = { - "email": "john.doe@example.com", - "email_verified": False, - "family_name": "Doe", - "given_name": "John", - "groups": ["/staff"], - "name": "John Doe", - "preferred_username": "johndoe", - "sub": "feacd344-b468-4a65-a236-14f61e6b7200", -} - RAW_REALM_PUBLIC_KEY = ( "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAnqF4xvGjaI54P6WtJvyGayxP8A93u" "NcA3TH6jitwmyAalj8dN8/NzK9vrdlSA3Ibvp/XQujPSOP7a35YiYFscEJnogTXQpE/FhZrUY"