CollectedClientDataConverter { public CollectedClientData convert(String base64UrlString) { if (base64UrlString == null) { return null; } byte[] bytes = Base64UrlUtil.decode(base64UrlString); return convert(bytes); } CollectedClientDataConverter(ObjectConverter objectConverter); CollectedClientData convert(String base64UrlString); CollectedClientData convert(byte[] source); byte[] convertToBytes(CollectedClientData source); String convertToBase64UrlString(CollectedClientData source);  }
@Test void convert_deserialization_test() { String clientDataJson = "{\"challenge\":\"tk31UH1ETGGTPj33OhOMzw\",\"origin\":\"http: String clientDataBase64UrlString = Base64UrlUtil.encodeToString(clientDataJson.getBytes(StandardCharsets.UTF_8)); CollectedClientData collectedClientData = target.convert(clientDataBase64UrlString); assertAll( () -> assertThat(collectedClientData.getType()).isEqualTo(ClientDataType.GET), () -> assertThat(collectedClientData.getChallenge()).isEqualTo(new DefaultChallenge("tk31UH1ETGGTPj33OhOMzw")), () -> assertThat(collectedClientData.getOrigin()).isEqualTo(new Origin("http: ); }
@Test void convert_null_test() { assertAll( () -> assertThat(target.convert((String) null)).isNull(), () -> assertThat(target.convert((byte[]) null)).isNull() ); }
@Test void convert_clientDataBase64UrlString_with_new_keys_test() { String clientDataJson = "{\"challenge\":\"Tgup0LZZQKinvtQcZFYdRw\",\"new_keys_may_be_added_here\":\"do not compare clientDataJSON against a template. See https: String clientDataBase64UrlString = Base64UrlUtil.encodeToString(clientDataJson.getBytes(StandardCharsets.UTF_8)); CollectedClientData collectedClientData = target.convert(clientDataBase64UrlString); assertAll( () -> assertThat(collectedClientData.getType()).isEqualTo(ClientDataType.CREATE), () -> assertThat(collectedClientData.getChallenge()).isEqualTo(new DefaultChallenge("Tgup0LZZQKinvtQcZFYdRw")), () -> assertThat(collectedClientData.getOrigin()).isEqualTo(new Origin("http: ); }
@Test void apk_key_hash_convert_clientDataBase64UrlString() { String clientDataJson = "{\n" + " \"type\": \"webauthn.create\",\n" + " \"challenge\": \"AAABcXKin1fLrZx0o4RL64fs-RUVSxCu\",\n" + " \"origin\": \"android:apk-key-hash:pNiP5iKyQ8JwgGOaKA1zGPUPJIS00H1xKCQcfIoGLck\",\n" + " \"androidPackageName\": \"com.myrpid.app\"\n" + "}"; String clientDataBase64UrlString = Base64UrlUtil.encodeToString(clientDataJson.getBytes(StandardCharsets.UTF_8)); CollectedClientData collectedClientData = target.convert(clientDataBase64UrlString); assertAll( () -> assertThat(collectedClientData.getType()).isEqualTo(ClientDataType.CREATE), () -> assertThat(collectedClientData.getTokenBinding()).isNull(), () -> assertThat(collectedClientData.getChallenge()).isEqualTo(new DefaultChallenge("AAABcXKin1fLrZx0o4RL64fs-RUVSxCu")), () -> assertThat(collectedClientData.getOrigin()).isEqualTo(new Origin("android:apk-key-hash:pNiP5iKyQ8JwgGOaKA1zGPUPJIS00H1xKCQcfIoGLck")) ); }
@Test void apk_key_hash_sha256_convert_clientDataBase64UrlString() { String clientDataJson = "{\n" + " \"type\": \"webauthn.create\",\n" + " \"challenge\": \"AAABcXKin1fLrZx0o4RL64fs-RUVSxCu\",\n" + " \"origin\": \"android:apk-key-hash-sha256:xT5ZucZJ9N7oq3j3awG8J/NlKf8trfo6AAJB8deuuNo=\",\n" + " \"androidPackageName\": \"com.myrpid.app\"\n" + "}"; String clientDataBase64UrlString = Base64UrlUtil.encodeToString(clientDataJson.getBytes(StandardCharsets.UTF_8)); CollectedClientData collectedClientData = target.convert(clientDataBase64UrlString); assertAll( () -> assertThat(collectedClientData.getType()).isEqualTo(ClientDataType.CREATE), () -> assertThat(collectedClientData.getTokenBinding()).isNull(), () -> assertThat(collectedClientData.getChallenge()).isEqualTo(new DefaultChallenge("AAABcXKin1fLrZx0o4RL64fs-RUVSxCu")), () -> assertThat(collectedClientData.getOrigin()).isEqualTo(new Origin("android:apk-key-hash-sha256:xT5ZucZJ9N7oq3j3awG8J/NlKf8trfo6AAJB8deuuNo=")) ); }