Skip to content

Commit

Permalink
Remove GaenControllerTestNotThreadSafe and put androidUserAgent strin…
Browse files Browse the repository at this point in the history
…g in class-variable
  • Loading branch information
ineiti committed Sep 1, 2020
1 parent 0c9f57b commit 7c0d208
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 247 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public void testRedeemUUID() {
assertTrue(actual);
}

// @Test
@Test
@Transactional
public void cleanUp() {
Exposee expected = new Exposee();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ public class GaenControllerTest extends BaseControllerTest {
@Autowired KeyVault keyVault;
@Autowired GAENDataService gaenDataService;
Long releaseBucketDuration = 7200000L;
private static final String androidUserAgent =
"ch.admin.bag.dp3t.dev;1.0.7;1595591959493;Android;29";

private static final Logger logger = LoggerFactory.getLogger(GaenControllerTest.class);

Expand Down Expand Up @@ -164,7 +166,7 @@ private void testNKeys(UTCInstant now, int n, boolean shouldSucceed) throws Exce
post("/v1/gaen/exposed")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer " + token)
.header("User-Agent", "ch.admin.bag.dp3t.dev;1.0.7;1595591959493;Android;29")
.header("User-Agent", androidUserAgent)
.content(json(requestList)));
MvcResult response;

Expand All @@ -181,7 +183,7 @@ private void testNKeys(UTCInstant now, int n, boolean shouldSucceed) throws Exce
post("/v1/gaen/exposed")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer " + jwtToken)
.header("User-Agent", "ch.admin.bag.dp3t.dev;1.0.7;1595591959493;Android;29")
.header("User-Agent", androidUserAgent)
.content(json(requestList)))
.andExpect(status().is(401))
.andExpect(request().asyncNotStarted())
Expand Down Expand Up @@ -247,7 +249,7 @@ public void testAllKeysWrongButStill200() throws Exception {
post("/v1/gaen/exposed")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer " + token)
.header("User-Agent", "ch.admin.bag.dp3t.dev;1.0.7;1595591959493;Android;29")
.header("User-Agent", androidUserAgent)
.content(json(requestList)))
.andExpect(request().asyncStarted())
.andReturn();
Expand All @@ -259,7 +261,7 @@ public void testAllKeysWrongButStill200() throws Exception {
post("/v1/gaen/exposed")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer " + jwtToken)
.header("User-Agent", "ch.admin.bag.dp3t.dev;1.0.7;1595591959493;Android;29")
.header("User-Agent", androidUserAgent)
.content(json(requestList)))
.andExpect(status().is(401))
.andExpect(request().asyncNotStarted())
Expand Down Expand Up @@ -317,7 +319,7 @@ public void testSecurityHeaders() throws Exception {
mockMvc
.perform(
get("/v1/gaen/exposed/" + midnight.minusDays(8).getTimestamp())
.header("User-Agent", "ch.admin.bag.dp3t.dev;1.0.7;1595591959493;Android;29"))
.header("User-Agent", androidUserAgent))
.andExpect(status().is2xxSuccessful())
.andReturn()
.getResponse();
Expand Down Expand Up @@ -368,7 +370,7 @@ public void testUploadWithNegativeRollingPeriodFails() throws Exception {
post("/v1/gaen/exposed")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer " + token)
.header("User-Agent", "ch.admin.bag.dp3t.dev;1.0.7;1595591959493;Android;29")
.header("User-Agent", androidUserAgent)
.content(json(requestList)))
.andExpect(request().asyncStarted())
.andReturn();
Expand Down Expand Up @@ -439,7 +441,7 @@ public void testMultipleKeyUploadFake() throws Exception {
post("/v1/gaen/exposed")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer " + token)
.header("User-Agent", "ch.admin.bag.dp3t.dev;1.0.7;1595591959493;Android;29")
.header("User-Agent", androidUserAgent)
.content(json(requestList)))
.andExpect(request().asyncStarted())
.andReturn();
Expand All @@ -450,7 +452,7 @@ public void testMultipleKeyUploadFake() throws Exception {
post("/v1/gaen/exposedlist")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer " + jwtToken)
.header("User-Agent", "ch.admin.bag.dp3t.dev;1.0.7;1595591959493;Android;29")
.header("User-Agent", androidUserAgent)
.content(json(requestList)))
.andExpect(status().is(401))
.andExpect(content().string(""))
Expand Down Expand Up @@ -506,7 +508,7 @@ public void testMultipleKeyUploadFakeAllKeysNeedToBeFake() throws Exception {
post("/v1/gaen/exposed")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer " + token)
.header("User-Agent", "ch.admin.bag.dp3t.dev;1.0.7;1595591959493;Android;29")
.header("User-Agent", androidUserAgent)
.content(json(requestList)))
.andExpect(request().asyncStarted())
.andReturn();
Expand All @@ -517,7 +519,7 @@ public void testMultipleKeyUploadFakeAllKeysNeedToBeFake() throws Exception {
post("/v1/gaen/exposedlist")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer " + jwtToken)
.header("User-Agent", "ch.admin.bag.dp3t.dev;1.0.7;1595591959493;Android;29")
.header("User-Agent", androidUserAgent)
.content(json(requestList)))
.andExpect(status().is(401))
.andExpect(content().string(""))
Expand Down Expand Up @@ -573,7 +575,7 @@ public void testMultipleKeyUploadFakeIfJWTNotFakeAllKeysCanBeFake() throws Excep
post("/v1/gaen/exposed")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer " + token)
.header("User-Agent", "ch.admin.bag.dp3t.dev;1.0.7;1595591959493;Android;29")
.header("User-Agent", androidUserAgent)
.content(json(requestList)))
.andExpect(request().asyncStarted())
.andReturn();
Expand All @@ -584,7 +586,7 @@ public void testMultipleKeyUploadFakeIfJWTNotFakeAllKeysCanBeFake() throws Excep
post("/v1/gaen/exposedlist")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer " + jwtToken)
.header("User-Agent", "ch.admin.bag.dp3t.dev;1.0.7;1595591959493;Android;29")
.header("User-Agent", androidUserAgent)
.content(json(requestList)))
.andExpect(status().is(401))
.andExpect(content().string(""))
Expand All @@ -607,7 +609,7 @@ public void testMultipleKeyNonEmptyUpload() throws Exception {
post("/v1/gaen/exposed")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer " + token)
.header("User-Agent", "ch.admin.bag.dp3t.dev;1.0.7;1595591959493;Android;29")
.header("User-Agent", androidUserAgent)
.content(json(requestList)))
.andExpect(request().asyncNotStarted())
.andExpect(status().is(400))
Expand All @@ -619,7 +621,7 @@ public void testMultipleKeyNonEmptyUpload() throws Exception {
post("/v1/gaen/exposedlist")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer " + jwtToken)
.header("User-Agent", "ch.admin.bag.dp3t.dev;1.0.7;1595591959493;Android;29")
.header("User-Agent", androidUserAgent)
.content(json(requestList)))
.andExpect(status().is(401))
.andExpect(content().string(""))
Expand All @@ -643,7 +645,7 @@ public void testMultipleKeyNonNullUpload() throws Exception {
post("/v1/gaen/exposed")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer " + token)
.header("User-Agent", "ch.admin.bag.dp3t.dev;1.0.7;1595591959493;Android;29")
.header("User-Agent", androidUserAgent)
.content(json(requestList)))
.andExpect(request().asyncNotStarted())
.andExpect(status().is(400))
Expand All @@ -655,7 +657,7 @@ public void testMultipleKeyNonNullUpload() throws Exception {
post("/v1/gaen/exposedlist")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer " + jwtToken)
.header("User-Agent", "ch.admin.bag.dp3t.dev;1.0.7;1595591959493;Android;29")
.header("User-Agent", androidUserAgent)
.content(json(requestList)))
.andExpect(status().is(401))
.andExpect(content().string(""))
Expand Down Expand Up @@ -697,7 +699,7 @@ public void keyNeedsToBeBase64() throws Exception {
post("/v1/gaen/exposed")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer " + token)
.header("User-Agent", "ch.admin.bag.dp3t.dev;1.0.7;1595591959493;Android;29")
.header("User-Agent", androidUserAgent)
.content(json(exposeeRequest)))
.andExpect(status().is(400))
.andReturn();
Expand Down Expand Up @@ -741,7 +743,7 @@ public void testKeyDateBeforeOnsetIsNotInserted() throws Exception {
post("/v1/gaen/exposed")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer " + token)
.header("User-Agent", "ch.admin.bag.dp3t.dev;1.0.7;1595591959493;Android;29")
.header("User-Agent", androidUserAgent)
.content(json(exposeeRequest)))
.andExpect(request().asyncStarted())
.andExpect(status().is(200))
Expand Down Expand Up @@ -791,7 +793,7 @@ public void cannotUseExpiredToken() throws Exception {
post("/v1/gaen/exposed")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer " + token)
.header("User-Agent", "ch.admin.bag.dp3t.dev;1.0.7;1595591959493;Android;29")
.header("User-Agent", androidUserAgent)
.content(json(exposeeRequest)))
.andExpect(request().asyncNotStarted())
.andExpect(status().is4xxClientError())
Expand Down Expand Up @@ -833,7 +835,7 @@ public void cannotUseKeyDateInFuture() throws Exception {
post("/v1/gaen/exposed")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer " + token)
.header("User-Agent", "ch.admin.bag.dp3t.dev;1.0.7;1595591959493;Android;29")
.header("User-Agent", androidUserAgent)
.content(json(exposeeRequest)))
.andExpect(status().is(200))
.andReturn();
Expand Down Expand Up @@ -881,7 +883,7 @@ public void keyDateNotOlderThan21Days() throws Exception {
post("/v1/gaen/exposed")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer " + token)
.header("User-Agent", "ch.admin.bag.dp3t.dev;1.0.7;1595591959493;Android;29")
.header("User-Agent", androidUserAgent)
.content(json(exposeeRequest)))
.andExpect(request().asyncStarted())
.andExpect(status().is(200))
Expand Down Expand Up @@ -929,7 +931,7 @@ public void cannotUseTokenWithWrongScope() throws Exception {
post("/v1/gaen/exposed")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer " + token)
.header("User-Agent", "ch.admin.bag.dp3t.dev;1.0.7;1595591959493;Android;29")
.header("User-Agent", androidUserAgent)
.content(json(exposeeRequest)))
.andExpect(status().is(403))
.andReturn();
Expand All @@ -941,7 +943,7 @@ public void cannotUseTokenWithWrongScope() throws Exception {
post("/v1/gaen/exposed")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer " + token)
.header("User-Agent", "ch.admin.bag.dp3t.dev;1.0.7;1595591959493;Android;29")
.header("User-Agent", androidUserAgent)
.content(json(exposeeRequest)))
.andExpect(request().asyncNotStarted())
.andExpect(status().is(401))
Expand Down Expand Up @@ -978,7 +980,7 @@ public void uploadKeysAndUploadKeyNextDay() throws Exception {
post("/v1/gaen/exposed")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer " + token)
.header("User-Agent", "ch.admin.bag.dp3t.dev;1.0.7;1595591959493;Android;29")
.header("User-Agent", androidUserAgent)
.content(json(exposeeRequest)))
.andExpect(request().asyncStarted())
.andReturn();
Expand Down Expand Up @@ -1010,7 +1012,7 @@ public void uploadKeysAndUploadKeyNextDay() throws Exception {
post("/v1/gaen/exposednextday")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer " + jwtString)
.header("User-Agent", "ch.admin.bag.dp3t.dev;1.0.7;1595591959493;Android;29")
.header("User-Agent", androidUserAgent)
.content(json(secondDay)))
.andExpect(request().asyncStarted())
.andReturn();
Expand Down Expand Up @@ -1047,7 +1049,7 @@ public void uploadKeysAndUploadKeyNextDayWithNegativeRollingPeriodFails() throws
post("/v1/gaen/exposed")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer " + token)
.header("User-Agent", "ch.admin.bag.dp3t.dev;1.0.7;1595591959493;Android;29")
.header("User-Agent", androidUserAgent)
.content(json(exposeeRequest)))
.andExpect(request().asyncStarted())
.andReturn();
Expand Down Expand Up @@ -1079,7 +1081,7 @@ public void uploadKeysAndUploadKeyNextDayWithNegativeRollingPeriodFails() throws
post("/v1/gaen/exposednextday")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer " + jwtString)
.header("User-Agent", "ch.admin.bag.dp3t.dev;1.0.7;1595591959493;Android;29")
.header("User-Agent", androidUserAgent)
.content(json(secondDay)))
.andExpect(request().asyncStarted())
.andReturn();
Expand Down Expand Up @@ -1126,8 +1128,7 @@ public void delayedKeyDateBoundaryCheck() throws Exception {
post("/v1/gaen/exposed")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer " + token)
.header(
"User-Agent", "ch.admin.bag.dp3t.dev;1.0.7;1595591959493;Android;29")
.header("User-Agent", androidUserAgent)
.content(json(exposeeRequest)))
.andExpect(request().asyncStarted())
.andReturn();
Expand All @@ -1143,8 +1144,7 @@ public void delayedKeyDateBoundaryCheck() throws Exception {
post("/v1/gaen/exposed")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer " + token)
.header(
"User-Agent", "ch.admin.bag.dp3t.dev;1.0.7;1595591959493;Android;29")
.header("User-Agent", androidUserAgent)
.content(json(exposeeRequest)))
.andExpect(status().is(400))
.andReturn();
Expand Down Expand Up @@ -1182,7 +1182,7 @@ public void testTokenValiditySurpassesMaxJwtValidity() throws Exception {
post("/v1/gaen/exposed")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer " + token)
.header("User-Agent", "ch.admin.bag.dp3t.dev;1.0.7;1595591959493;Android;29")
.header("User-Agent", androidUserAgent)
.content(json(exposeeRequest)))
.andExpect(status().is(401));
}
Expand All @@ -1206,7 +1206,7 @@ public void testDebugController() throws Exception {
mockMvc
.perform(
get("/v1/debug/exposed/" + midnight.getTimestamp())
.header("User-Agent", "ch.admin.bag.dp3t.dev;1.0.7;1595591959493;Android;29"))
.header("User-Agent", androidUserAgent))
.andExpect(status().is2xxSuccessful())
.andReturn()
.getResponse();
Expand Down Expand Up @@ -1274,7 +1274,7 @@ public void testNonEmptyResponseAnd304() throws Exception {
mockMvc
.perform(
get("/v1/gaen/exposed/" + midnight.minusDays(8).getTimestamp())
.header("User-Agent", "ch.admin.bag.dp3t.dev;1.0.7;1595591959493;Android;29"))
.header("User-Agent", androidUserAgent))
.andExpect(status().isOk())
.andReturn()
.getResponse();
Expand Down Expand Up @@ -1308,7 +1308,7 @@ public void testEtag() throws Exception {
mockMvc
.perform(
get("/v1/gaen/exposed/" + midnight.minusDays(8).getTimestamp())
.header("User-Agent", "ch.admin.bag.dp3t.dev;1.0.7;1595591959493;Android;29"))
.header("User-Agent", androidUserAgent))
.andExpect(status().is2xxSuccessful())
.andReturn()
.getResponse();
Expand All @@ -1321,7 +1321,7 @@ public void testEtag() throws Exception {
mockMvc
.perform(
get("/v1/gaen/exposed/" + midnight.minusDays(8).getTimestamp())
.header("User-Agent", "ch.admin.bag.dp3t.dev;1.0.7;1595591959493;Android;29"))
.header("User-Agent", androidUserAgent))
.andExpect(status().is2xxSuccessful())
.andReturn()
.getResponse();
Expand All @@ -1336,7 +1336,7 @@ public void testEtag() throws Exception {
mockMvc
.perform(
get("/v1/gaen/exposed/" + midnight.minusDays(8).getTimestamp())
.header("User-Agent", "ch.admin.bag.dp3t.dev;1.0.7;1595591959493;Android;29"))
.header("User-Agent", androidUserAgent))
.andExpect(status().is2xxSuccessful())
.andReturn()
.getResponse();
Expand Down
Loading

0 comments on commit 7c0d208

Please sign in to comment.