Skip to content

Commit 6e3e710

Browse files
Better AdminUserService tests (for getUser)
* actually checks if the HTTP client passes the correct headers * `X-API-KEY` * `TYLER-TOKEN-ILLINOIS` * `TYLER-ID-ILLINOIS` * Fixes an issue in the AdminUserService where we would grab the wrong header for the current User ID to pass to `getUser()`. It seems to have been working fine in all environments (stage, prod, etc.), but the documentation says to pass the User ID, so I fixed that.
1 parent 549a1e3 commit 6e3e710

2 files changed

Lines changed: 72 additions & 5 deletions

File tree

proxyserver/src/main/java/edu/suffolk/litlab/efsp/server/services/AdminUserService.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,17 +163,16 @@ public Response getSelfUser(@Context HttpHeaders httpHeaders) {
163163
if (port.isEmpty()) {
164164
return Response.status(401).build();
165165
}
166-
String tylerId =
167-
httpHeaders.getHeaderString(TylerLogin.getHeaderKeyFromJurisdiction(jurisdiction));
168-
if (tylerId == null || tylerId.isBlank()) {
166+
String userId = httpHeaders.getHeaderString(TylerLogin.getHeaderId(jurisdiction));
167+
if (userId == null || userId.isBlank()) {
169168
return Response.status(500)
170169
.entity(
171170
"Server does not have a Tyler UUID for the current account. Can you give it to me?")
172171
.build();
173172
}
174173

175174
GetUserRequestType req = new GetUserRequestType();
176-
req.setUserID(tylerId);
175+
req.setUserID(userId);
177176
GetUserResponseType resp = port.get().getUser(req);
178177
return makeResponse(resp, () -> Response.ok(resp.getUser()).build());
179178
}

proxyserver/src/test/java/edu/suffolk/litlab/efsp/server/services/AdminUserServiceTest.java

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import static org.assertj.core.api.Assertions.assertThat;
44
import static org.mockito.ArgumentMatchers.any;
5+
import static org.mockito.ArgumentMatchers.eq;
56
import static org.mockito.Mockito.mock;
67
import static org.mockito.Mockito.when;
78

@@ -38,11 +39,14 @@
3839
import org.mockito.MockedStatic;
3940
import org.mockito.Mockito;
4041
import tyler.efm.latest.services.schema.common.ErrorType;
42+
import tyler.efm.latest.services.schema.common.UserType;
43+
import tyler.efm.latest.services.schema.getuserresponse.GetUserResponseType;
4144
import tyler.efm.latest.services.schema.registrationresponse.RegistrationResponseType;
4245

4346
public class AdminUserServiceTest {
4447

4548
private static final String ENDPOINT_ADDRESS = "http://localhost:9090";
49+
private static final String API_KEY = "abc123";
4650
private Server server;
4751
private WebClient client;
4852

@@ -74,7 +78,7 @@ private void startServer() {
7478
atRest.serverId = UUID.randomUUID();
7579
atRest.enabled = Map.of("tyler", true, "jeffnet", true);
7680
ld = mock(LoginDatabase.class);
77-
when(ld.getAtRestInfo(any())).thenReturn(Optional.of(new AtRest()));
81+
when(ld.getAtRestInfo(eq(API_KEY))).thenReturn(Optional.of(atRest));
7882

7983
CourtLocationInfo info = new CourtLocationInfo();
8084
info.allowindividualregistration = true;
@@ -123,6 +127,14 @@ static void destroy() {
123127
mockClients.close();
124128
}
125129

130+
@Test
131+
public void testNoApiKey() {
132+
client.path("/users");
133+
134+
Response resp = client.post("{\"registrationType\": \"INDIVIDUAL\"}");
135+
assertThat(resp.getStatus()).isEqualTo(401);
136+
}
137+
126138
@Nested
127139
class RegisterUserTest {
128140

@@ -139,6 +151,7 @@ class RegisterUserTest {
139151
@BeforeEach
140152
public void setup() {
141153
client.path("/users");
154+
client.header("X-API-KEY", API_KEY);
142155
}
143156

144157
@Test
@@ -201,4 +214,59 @@ public void testBadPassword() {
201214
assertThat(resp.readEntity(String.class)).isEqualTo("Password can't be password");
202215
}
203216
}
217+
218+
@Nested
219+
class GetUserTest {
220+
@BeforeEach
221+
public void setup() {
222+
client.path("/user");
223+
client.header("X-API-KEY", API_KEY);
224+
225+
GetUserResponseType soapResp = new GetUserResponseType();
226+
var user = new UserType();
227+
user.setEmail("bob@example.com");
228+
soapResp.setUser(user);
229+
var err = new ErrorType();
230+
err.setErrorCode("0");
231+
soapResp.setError(err);
232+
when(tylerUserClient.getUser(any())).thenReturn(soapResp);
233+
}
234+
235+
@Test
236+
public void testNoTylerJurisdictionHeader() {
237+
Response resp = client.get();
238+
assertThat(resp.getStatus()).isEqualTo(401);
239+
}
240+
241+
@Test
242+
public void testNoTylerUserIdHeader() {
243+
Response resp = client.header("TYLER-TOKEN-ILLINOIS", "bob@example.com:abc123").get();
244+
assertThat(resp.getStatus()).isEqualTo(500);
245+
assertThat(resp.readEntity(String.class)).contains("Server does not have a Tyler UUID");
246+
}
247+
248+
@Test
249+
public void testWithAllHeadersCaseInsensitive() {
250+
client.removeAllHeaders();
251+
client.header("X-API-KEY", API_KEY);
252+
client.header("TYLER-TOKEN-ILLINOIS", "bob@example.com:abc123");
253+
client.header("TYLER-ID-ILLINOIS", "12345678-abcd-1234-abcd-12345678abcd");
254+
var resp = client.get();
255+
assertThat(resp.getStatus()).isEqualTo(200);
256+
257+
client.removeAllHeaders();
258+
client.header("X-API-KEY", API_KEY);
259+
client.header("TYLER-TOKEN-ILLINOIS", "bob@example.com:abc123");
260+
client.header("TYLER-ID-illinois", "12345678-abcd-1234-abcd-12345678abcd");
261+
resp = client.get();
262+
assertThat(resp.getStatus()).isEqualTo(200);
263+
264+
client.removeAllHeaders();
265+
client.header("X-API-KEY", API_KEY);
266+
client.header("TYLER-TOKEN-ILLINOIS", "bob@example.com:abc123");
267+
client.header("TYLER-ID-Illinois", "12345678-abcd-1234-abcd-12345678abcd");
268+
resp = client.get();
269+
assertThat(resp.getStatus()).isEqualTo(200);
270+
}
271+
}
204272
}

0 commit comments

Comments
 (0)