From ffdcb1105a2304f32e7e487de2b487e56d53c053 Mon Sep 17 00:00:00 2001 From: Sina Madani Date: Thu, 17 Oct 2024 16:34:07 +0100 Subject: [PATCH] feat: Add Rtc.signed_callbacks field --- .../client/application/capabilities/Rtc.java | 37 +++++++++++++++++++ .../application/ApplicationClientTest.java | 4 +- .../application/capabilities/RtcTest.java | 9 ++++- 3 files changed, 47 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/vonage/client/application/capabilities/Rtc.java b/src/main/java/com/vonage/client/application/capabilities/Rtc.java index be7081367..87474334b 100644 --- a/src/main/java/com/vonage/client/application/capabilities/Rtc.java +++ b/src/main/java/com/vonage/client/application/capabilities/Rtc.java @@ -15,18 +15,21 @@ */ package com.vonage.client.application.capabilities; +import com.fasterxml.jackson.annotation.JsonProperty; import com.vonage.client.common.Webhook; /** * Rtc capability configuration settings. */ public final class Rtc extends Capability { + private Boolean signedCallbacks; private Rtc() { } private Rtc(Builder builder) { super(builder); + this.signedCallbacks = builder.signedCallbacks; } @Override @@ -34,6 +37,18 @@ public Type getType() { return Type.RTC; } + /** + * Whether to use signed webhooks. This is a way of verifying that the request is coming from Vonage. + * + * @return {@code true} if signed webhooks are used, {@code false} if not and {@code null} if unknown. + * + * @since 8.12.0 + */ + @JsonProperty("signed_callbacks") + public Boolean getSignedCallbacks() { + return signedCallbacks; + } + /** * Entry point for constructing an instance of this class. * @@ -44,6 +59,28 @@ public static Builder builder() { } public static class Builder extends Capability.Builder { + private Boolean signedCallbacks; + + /** + * Constructs a new Builder. + * + * @deprecated Use {@link #builder()} instead. This constructor will be made private in a future release. + */ + @Deprecated + public Builder() { + } + + /** + * Set whether to use signed webhooks. This is a way of verifying that the request is coming from Vonage. + * + * @param signedCallbacks {@code true} if signed webhooks should be used. + * @return This builder. + * @since 8.12.0 + */ + public Builder signedCallbacks(boolean signedCallbacks) { + this.signedCallbacks = signedCallbacks; + return this; + } @Override public Builder addWebhook(Webhook.Type type, Webhook webhook) { diff --git a/src/test/java/com/vonage/client/application/ApplicationClientTest.java b/src/test/java/com/vonage/client/application/ApplicationClientTest.java index 9a18c0acf..1f2db3f2b 100644 --- a/src/test/java/com/vonage/client/application/ApplicationClientTest.java +++ b/src/test/java/com/vonage/client/application/ApplicationClientTest.java @@ -84,7 +84,8 @@ public class ApplicationClientTest extends AbstractClientTest " \"address\": \"https://example.com/webhooks/event\",\n" + " \"http_method\": \"POST\"\n" + " }\n" + - " }\n" + + " },\n" + + " \"signed_callbacks\": true\n" + " },\n" + " \"vbc\": {},\n" + " \"verify\": {\n" + @@ -147,6 +148,7 @@ static void assertEqualsSampleApplication(Application response) { assertEquals(Capability.Type.RTC, rtc.getType()); assertEquals("https://example.com/webhooks/event", rtc.getWebhooks().get(Webhook.Type.EVENT).getAddress()); assertEquals(HttpMethod.POST, rtc.getWebhooks().get(Webhook.Type.EVENT).getMethod()); + assertTrue(rtc.getSignedCallbacks()); Vbc vbc = capabilities.getVbc(); assertEquals(Capability.Type.VBC, vbc.getType()); diff --git a/src/test/java/com/vonage/client/application/capabilities/RtcTest.java b/src/test/java/com/vonage/client/application/capabilities/RtcTest.java index 216a3a5da..cb4d3d681 100644 --- a/src/test/java/com/vonage/client/application/capabilities/RtcTest.java +++ b/src/test/java/com/vonage/client/application/capabilities/RtcTest.java @@ -27,14 +27,18 @@ public void testEmpty() { assertEquals(Capability.Type.RTC, rtc.getType()); assertNull(rtc.getWebhooks()); + assertNull(rtc.getSignedCallbacks()); } @Test public void testEventWebhook() { - Rtc rtc = Rtc.builder().addWebhook(Webhook.Type.EVENT, new Webhook("https://example.com/event", HttpMethod.GET)).build(); + Rtc rtc = Rtc.builder() + .addWebhook(Webhook.Type.EVENT, new Webhook("https://example.com/event", HttpMethod.GET)) + .signedCallbacks(true).build(); assertEquals(Capability.Type.RTC, rtc.getType()); assertEquals("https://example.com/event", rtc.getWebhooks().get(Webhook.Type.EVENT).getAddress()); + assertTrue(rtc.getSignedCallbacks()); assertEquals(HttpMethod.GET, rtc.getWebhooks().get(Webhook.Type.EVENT).getMethod()); } @@ -43,9 +47,10 @@ public void testRemoveWebhook() { Rtc rtc = Rtc.builder() .addWebhook(Webhook.Type.EVENT, new Webhook("https://example.com/event", HttpMethod.POST)) .removeWebhook(Webhook.Type.EVENT) - .build(); + .signedCallbacks(false).build(); assertEquals(Capability.Type.RTC, rtc.getType()); + assertFalse(rtc.getSignedCallbacks()); assertNull(rtc.getWebhooks()); } }