@@ -102,15 +102,71 @@ async def test_user_role_unhappy_path(self, test_app_and_product,
102102
103103 @pytest .mark .mock_auth
104104 @pytest .mark .asyncio
105+ @pytest .mark .parametrize ("additional_headers,error_description" , [
106+ (
107+ {},
108+ "selected_roleid is missing in your token"
109+ ),
110+ (
111+ {"NHSD-Session-URID" : "656014452101" },
112+ "unable to retrieve user info"
113+ )
114+ ])
105115 async def test_nhs_login_exchanged_token_no_role_provided (
106- self , get_token_nhs_login_token_exchange
116+ self ,
117+ get_token_nhs_login_token_exchange ,
118+ additional_headers ,
119+ error_description
107120 ):
108121 token = get_token_nhs_login_token_exchange ["access_token" ]
122+ headers = {
123+ "Authorization" : f"Bearer { token } " ,
124+ }
125+ for key , value in additional_headers .items ():
126+ headers [key ] = value
109127
110128 response = requests .get (
111129 url = f"https://internal-dev.api.service.nhs.uk/{ config .SERVICE_BASE_PATH } /user-role-service" ,
112- headers = {"Authorization" : f"Bearer { token } " },
130+ headers = headers
131+ )
132+
133+ assert response .status_code == 400
134+ assert response .json ()["issue" ][0 ]["diagnostics" ] == error_description
135+
136+ @pytest .mark .simulated_auth
137+ @pytest .mark .asyncio
138+ async def test_cis2_exchanged_token_happy_path (
139+ self ,
140+ get_token_cis2_token_exchange
141+ ):
142+ token = get_token_cis2_token_exchange ["access_token" ]
143+ headers = {
144+ "Authorization" : f"Bearer { token } " ,
145+ }
146+
147+ response = requests .get (
148+ url = f"https://internal-dev.api.service.nhs.uk/{ config .SERVICE_BASE_PATH } /user-role-service" ,
149+ headers = headers
150+ )
151+
152+ assert response .status_code == 200
153+
154+ @pytest .mark .simulated_auth
155+ @pytest .mark .asyncio
156+ async def test_cis2_exchanged_token_no_role_provided (
157+ self ,
158+ get_token_cis2_token_exchange
159+ ):
160+ token = get_token_cis2_token_exchange ["access_token" ]
161+ headers = {
162+ "Authorization" : f"Bearer { token } " ,
163+ "NHSD-Session-URID" : "656014452101"
164+ }
165+
166+ response = requests .get (
167+ url = f"https://internal-dev.api.service.nhs.uk/{ config .SERVICE_BASE_PATH } /user-role-service" ,
168+ headers = headers
113169 )
114170
115171 assert response .status_code == 400
116- assert response .json ()["issue" ][0 ]["diagnostics" ] == "selected_roleid is missing in your token "
172+ assert response .json ()["issue" ][0 ]["diagnostics" ] == "unable to retrieve user info "
0 commit comments