-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #395 from IABTechLab/ccm-UID2-2165-log-Origin-fiel…
…d-for-InvalidHttpOrigin-errors UID2-2165 Log origin field for InvalidHttpOrigin errors
- Loading branch information
Showing
8 changed files
with
141 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
package com.uid2.operator; | ||
|
||
import ch.qos.logback.classic.Logger; | ||
import ch.qos.logback.classic.spi.ILoggingEvent; | ||
import ch.qos.logback.core.read.ListAppender; | ||
import com.uid2.operator.model.*; | ||
import com.uid2.operator.model.IdentityScope; | ||
import com.uid2.operator.monitoring.IStatsCollectorQueue; | ||
|
@@ -48,6 +51,7 @@ | |
import org.mockito.ArgumentCaptor; | ||
import org.mockito.Mock; | ||
import org.mockito.MockitoAnnotations; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import javax.crypto.SecretKey; | ||
import java.math.BigInteger; | ||
|
@@ -148,6 +152,7 @@ private void setupConfig(JsonObject config) { | |
config.put("identity_v3", useIdentityV3()); | ||
config.put("client_side_token_generate", true); | ||
config.put("key_sharing_endpoint_provide_site_domain_names", true); | ||
config.put("client_side_token_generate_log_invalid_http_origins", true); | ||
} | ||
|
||
private static byte[] makeAesKey(String prefix) { | ||
|
@@ -2723,6 +2728,80 @@ void cstgDomainNameCheckFails(boolean setOptoutCheckFlagInRequest, String httpOr | |
}); | ||
} | ||
|
||
@ParameterizedTest | ||
@CsvSource({ | ||
"true,http://gototest.com", | ||
"false,http://gototest.com", | ||
}) | ||
void cstgDomainNameCheckFailsAndLogInvalidHttpOrigin(boolean setOptoutCheckFlagInRequest, String httpOrigin, Vertx vertx, VertxTestContext testContext) throws NoSuchAlgorithmException, InvalidKeyException { | ||
ListAppender<ILoggingEvent> logWatcher = new ListAppender<>(); | ||
logWatcher.start(); | ||
((Logger) LoggerFactory.getLogger(UIDOperatorVerticle.class)).addAppender(logWatcher); | ||
this.uidOperatorVerticle.setLastInvalidOriginProcessTime(Instant.now().minusSeconds(3600)); | ||
|
||
setupCstgBackend(); | ||
Tuple.Tuple2<JsonObject, SecretKey> data = createClientSideTokenGenerateRequest(IdentityType.Email, "[email protected]", Instant.now().toEpochMilli(), setOptoutCheckFlagInRequest); | ||
sendCstg(vertx, | ||
"v2/token/client-generate", | ||
httpOrigin, | ||
data.getItem1(), | ||
data.getItem2(), | ||
403, | ||
testContext, | ||
respJson -> { | ||
assertFalse(respJson.containsKey("body")); | ||
assertEquals("unexpected http origin", respJson.getString("message")); | ||
assertEquals("invalid_http_origin", respJson.getString("status")); | ||
Assertions.assertTrue(logWatcher.list.get(0).getFormattedMessage().contains("InvalidHttpOrigin: site test (123): http://gototest.com")); | ||
assertTokenStatusMetrics( | ||
clientSideTokenGenerateSiteId, | ||
TokenResponseStatsCollector.Endpoint.ClientSideTokenGenerateV2, | ||
TokenResponseStatsCollector.ResponseStatus.InvalidHttpOrigin); | ||
testContext.completeNow(); | ||
}); | ||
} | ||
|
||
@ParameterizedTest | ||
@CsvSource({ | ||
"true,http://gototest.com", | ||
"false,http://gototest.com", | ||
}) | ||
void cstgDomainNameCheckFailsAndLogSeveralInvalidHttpOrigin(boolean setOptoutCheckFlagInRequest, String httpOrigin, Vertx vertx, VertxTestContext testContext) throws NoSuchAlgorithmException, InvalidKeyException { | ||
ListAppender<ILoggingEvent> logWatcher = new ListAppender<>(); | ||
logWatcher.start(); | ||
((Logger) LoggerFactory.getLogger(UIDOperatorVerticle.class)).addAppender(logWatcher); | ||
this.uidOperatorVerticle.setLastInvalidOriginProcessTime(Instant.now().minusSeconds(3600)); | ||
|
||
Map<Integer, Set<String>> siteIdToInvalidOrigins = new HashMap<>(); | ||
siteIdToInvalidOrigins.put(clientSideTokenGenerateSiteId, new HashSet<>(Arrays.asList("http://localhost1.com", "http://localhost2.com"))); | ||
siteIdToInvalidOrigins.put(124, new HashSet<>(Arrays.asList("http://xyz1.com", "http://xyz2.com"))); | ||
|
||
this.uidOperatorVerticle.setSiteIdToInvalidOrigins(siteIdToInvalidOrigins); | ||
|
||
setupCstgBackend(); | ||
when(siteProvider.getSite(124)).thenReturn(new Site(124, "test2", true, new HashSet<>())); | ||
|
||
Tuple.Tuple2<JsonObject, SecretKey> data = createClientSideTokenGenerateRequest(IdentityType.Email, "[email protected]", Instant.now().toEpochMilli(), setOptoutCheckFlagInRequest); | ||
sendCstg(vertx, | ||
"v2/token/client-generate", | ||
httpOrigin, | ||
data.getItem1(), | ||
data.getItem2(), | ||
403, | ||
testContext, | ||
respJson -> { | ||
assertFalse(respJson.containsKey("body")); | ||
assertEquals("unexpected http origin", respJson.getString("message")); | ||
assertEquals("invalid_http_origin", respJson.getString("status")); | ||
Assertions.assertTrue(logWatcher.list.get(0).getFormattedMessage().contains("InvalidHttpOrigin: site test (123): http://localhost1.com, http://gototest.com, http://localhost2.com | site test2 (124): http://xyz1.com, http://xyz2.com")); | ||
assertTokenStatusMetrics( | ||
clientSideTokenGenerateSiteId, | ||
TokenResponseStatsCollector.Endpoint.ClientSideTokenGenerateV2, | ||
TokenResponseStatsCollector.ResponseStatus.InvalidHttpOrigin); | ||
testContext.completeNow(); | ||
}); | ||
} | ||
|
||
@ParameterizedTest | ||
@CsvSource({ | ||
"true,https://cstg.co.uk", | ||
|