-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DBZ-8063 refactor webhook MAC initialization
- Rename 'standard_webhooks' namespace to 'webhooks' - Use Clock for testing webhook timestamp - Refactor Authenticator config initialization
- Loading branch information
1 parent
deb3aae
commit 1ad1032
Showing
6 changed files
with
122 additions
and
111 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
67 changes: 0 additions & 67 deletions
67
...est/java/io/debezium/server/http/standard_webhooks/StandardWebhooksAuthenticatorTest.java
This file was deleted.
Oops, something went wrong.
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
58 changes: 58 additions & 0 deletions
58
...ttp/src/test/java/io/debezium/server/http/webhooks/StandardWebhooksAuthenticatorTest.java
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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright Debezium Authors. | ||
* | ||
* Licensed under the Apache Software License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
package io.debezium.server.http.webhooks; | ||
|
||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
import java.net.http.HttpHeaders; | ||
import java.net.http.HttpRequest; | ||
import java.time.Clock; | ||
import java.time.Instant; | ||
import java.time.ZoneOffset; | ||
import java.util.Optional; | ||
import java.util.UUID; | ||
|
||
import org.junit.Test; | ||
import org.junit.jupiter.api.Assertions; | ||
|
||
public class StandardWebhooksAuthenticatorTest { | ||
|
||
@Test | ||
public void addAuthorizationHeader() throws URISyntaxException { | ||
Clock clock = Clock.fixed(Instant.ofEpochSecond(1234), ZoneOffset.UTC); | ||
UUID messageId = UUID.fromString("22bd292a-71ab-46fe-a460-8632d6754ac6"); | ||
StandardWebhooksAuthenticator authenticator = new StandardWebhooksAuthenticator( | ||
"whsec_MfKQ9r8GKYqrTwjUPD8ILPZIo2LaLaSw", clock); | ||
|
||
URI testURI = new URI("http://example.com"); | ||
String testEventContent = "{\"hello\":\"world\"}"; | ||
HttpRequest.Builder builder = HttpRequest.newBuilder(testURI); | ||
builder.POST(HttpRequest.BodyPublishers.ofString(testEventContent)); | ||
authenticator.setAuthorizationHeader(builder, testEventContent, messageId); | ||
HttpRequest request = builder.build(); | ||
|
||
HttpHeaders headers = request.headers(); | ||
|
||
Optional<String> idHeader = headers.firstValue("webhook-id"); | ||
Assertions.assertTrue(idHeader.isPresent()); | ||
Assertions.assertEquals("msg_22bd292a-71ab-46fe-a460-8632d6754ac6", idHeader.get()); | ||
|
||
Optional<String> timestampHeader = headers.firstValue("webhook-timestamp"); | ||
Assertions.assertTrue(timestampHeader.isPresent()); | ||
Assertions.assertEquals("1234", timestampHeader.get()); | ||
|
||
Optional<String> signatureHeader = headers.firstValue("webhook-signature"); | ||
Assertions.assertTrue(signatureHeader.isPresent()); | ||
String[] sigParts = signatureHeader.get().split(","); | ||
Assertions.assertEquals(2, sigParts.length); | ||
Assertions.assertEquals("v1", sigParts[0]); | ||
|
||
// https://www.standardwebhooks.com/verify | ||
String expected = "v1,qCVBRIv6rKQVhSJBAmUSE9GkdCdPe2j6xzzkm89UcoA="; | ||
|
||
Assertions.assertEquals(expected, signatureHeader.get()); | ||
} | ||
} |