OriginValidator { public void validate(CollectedClientData collectedClientData, ServerProperty serverProperty) { final Origin clientOrigin = collectedClientData.getOrigin(); if (!serverProperty.getOrigins().contains(clientOrigin)) { throw new BadOriginException("The collectedClientData '" + clientOrigin + "' origin doesn't match any of the preconfigured server origin."); } }  void validate(CollectedClientData collectedClientData, ServerProperty serverProperty);  }
@Test void multiple_origins_test(){ final Origin originA = new Origin("https: final Origin originB = new Origin("http: final Origin originC = new Origin("android:apk-key-hash:pNiP5iKyQ8JwgGOaKA1zGPUPJIS-0H1xKCQcfIoGLck"); final Origin originD = new Origin("android:apk-key-hash-sha256:qSiQ5iKyQ8JwgGOaKA1zGPUPJIS-0H1xKCQcfIoGLck"); final ServerProperty serverProperty = new ServerProperty(Arrays.asList(originA,originB,originC,originD), "example.com", TestDataUtil.createChallenge(), null); final CollectedClientData collectedClientDataA = new CollectedClientData(ClientDataType.CREATE, TestDataUtil.createChallenge(), originA, null); final CollectedClientData collectedClientDataB = new CollectedClientData(ClientDataType.CREATE, TestDataUtil.createChallenge(), originB, null); final CollectedClientData collectedClientDataC = new CollectedClientData(ClientDataType.GET, TestDataUtil.createChallenge(), originC, null); final CollectedClientData collectedClientDataD = new CollectedClientData(ClientDataType.GET, TestDataUtil.createChallenge(), originD, null); target.validate(collectedClientDataA,serverProperty); target.validate(collectedClientDataB,serverProperty); target.validate(collectedClientDataC,serverProperty); target.validate(collectedClientDataD,serverProperty); }
@Test void multiple_origins_test_with_invalid_origin(){ final Origin originA = new Origin("https: final Origin originB = new Origin("http: final Origin originC = new Origin("android:apk-key-hash:pNiP5iKyQ8JwgGOaKA1zGPUPJIS-0H1xKCQcfIoGLck"); final Origin originD = new Origin("android:apk-key-hash-sha256:qSiQ5iKyQ8JwgGOaKA1zGPUPJIS-0H1xKCQcfIoGLck"); final Origin badOriginA = new Origin("https: final Origin badOriginB = new Origin("http: final Origin badOriginC = new Origin("android:apk-key-hash:0pNiP5iKyQ8JwgGOaKA1zGPUPJIS-0H1xKCQcfIoGLck"); final Origin badOriginD = new Origin("android:apk-key-hash-sha256:0qSiQ5iKyQ8JwgGOaKA1zGPUPJIS-0H1xKCQcfIoGLck"); final ServerProperty serverProperty = new ServerProperty(Arrays.asList(originA,originB,originC,originD), "example.com", TestDataUtil.createChallenge(), null); final CollectedClientData collectedClientDataA = new CollectedClientData(ClientDataType.CREATE, TestDataUtil.createChallenge(), badOriginA, null); final CollectedClientData collectedClientDataB = new CollectedClientData(ClientDataType.CREATE, TestDataUtil.createChallenge(), badOriginB, null); final CollectedClientData collectedClientDataC = new CollectedClientData(ClientDataType.GET, TestDataUtil.createChallenge(), badOriginC, null); final CollectedClientData collectedClientDataD = new CollectedClientData(ClientDataType.GET, TestDataUtil.createChallenge(), badOriginD, null); assertThrows(BadOriginException.class, () -> target.validate(collectedClientDataA, serverProperty) ); assertThrows(BadOriginException.class, () -> target.validate(collectedClientDataB, serverProperty) ); assertThrows(BadOriginException.class, () -> target.validate(collectedClientDataC, serverProperty) ); assertThrows(BadOriginException.class, () -> target.validate(collectedClientDataD, serverProperty) ); }
@Test void test_with_not_equal_origins() { Origin originA = new Origin("https: Origin originB = new Origin("http: CollectedClientData collectedClientData = new CollectedClientData(ClientDataType.CREATE, TestDataUtil.createChallenge(), originA, null); ServerProperty serverProperty = new ServerProperty(originB, "example.com", TestDataUtil.createChallenge(), null); assertThrows(BadOriginException.class, () -> target.validate(collectedClientData, serverProperty) ); }
@Test void apk_key_hash_test_with_not_equal_origins() { Origin originA = new Origin("android:apk-key-hash:aNiP5iKyQ8JwgGOaKA1zGPUPJIS-0H1xKCQcfIoGLck"); Origin originB = new Origin("android:apk-key-hash:pNiP5iKyQ8JwgGOaKA1zGPUPJIS-0H1xKCQcfIoGLck"); CollectedClientData collectedClientData = new CollectedClientData(ClientDataType.CREATE, TestDataUtil.createChallenge(), originA, null); ServerProperty serverProperty = new ServerProperty(originB, "example.com", TestDataUtil.createChallenge(), null); assertThrows(BadOriginException.class, () -> target.validate(collectedClientData, serverProperty) ); }
@Test void apk_key_hash_sha256_test_with_not_equal_origins() { Origin originA = new Origin("android:apk-key-hash-sha256:aNiP5iKyQ8JwgGOaKA1zGPUPJIS-0H1xKCQcfIoGLck"); Origin originB = new Origin("android:apk-key-hash-sha256:pNiP5iKyQ8JwgGOaKA1zGPUPJIS-0H1xKCQcfIoGLck"); CollectedClientData collectedClientData = new CollectedClientData(ClientDataType.CREATE, TestDataUtil.createChallenge(), originA, null); ServerProperty serverProperty = new ServerProperty(originB, "example.com", TestDataUtil.createChallenge(), null); assertThrows(BadOriginException.class, () -> target.validate(collectedClientData, serverProperty) ); }
@Test void apk_key_hash_sha256_test_with_not_equal_origins_apk_key_hash_sha1() { Origin originA = new Origin("android:apk-key-hash-sha256:aNiP5iKyQ8JwgGOaKA1zGPUPJIS-0H1xKCQcfIoGLck"); Origin originB = new Origin("android:apk-key-hash:pNiP5iKyQ8JwgGOaKA1zGPUPJIS-0H1xKCQcfIoGLck"); CollectedClientData collectedClientData = new CollectedClientData(ClientDataType.CREATE, TestDataUtil.createChallenge(), originA, null); ServerProperty serverProperty = new ServerProperty(originB, "example.com", TestDataUtil.createChallenge(), null); assertThrows(BadOriginException.class, () -> target.validate(collectedClientData, serverProperty) ); }
@Test void apk_key_hash_sha1_test_with_not_equal_origins_apk_key_hash_sha256() { Origin originA = new Origin("android:apk-key-hash:aNiP5iKyQ8JwgGOaKA1zGPUPJIS-0H1xKCQcfIoGLck"); Origin originB = new Origin("android:apk-key-hash-sha256:pNiP5iKyQ8JwgGOaKA1zGPUPJIS-0H1xKCQcfIoGLck"); CollectedClientData collectedClientData = new CollectedClientData(ClientDataType.CREATE, TestDataUtil.createChallenge(), originA, null); ServerProperty serverProperty = new ServerProperty(originB, "example.com", TestDataUtil.createChallenge(), null); assertThrows(BadOriginException.class, () -> target.validate(collectedClientData, serverProperty) ); }