Skip to content

Commit

Permalink
Fix Silent Auth URL deserialisation (#461)
Browse files Browse the repository at this point in the history
* Fixed Silent Auth action deser

* Improved getSupportedMessageTypes

* Updated changelog

* Bump version: v7.4.0 → v7.5.0

* Updated dependencies
  • Loading branch information
SMadani authored Jun 5, 2023
1 parent 51d969a commit db1a4fc
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[bumpversion]
commit = True
tag = False
current_version = v7.4.0
current_version = v7.5.0
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\-(?P<release>[a-z]+)(?P<build>\d+))?
serialize =
{major}.{minor}.{patch}-{release}{build}
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

# [7.5.0] - 2023-06
- Added custom PIN functionality to Verify v1
- Fixed Silent Auth action URL webhook deserialization issue

# [7.4.0] - 2023-05-18
- Added Verify v2 API implementation
- Added Advanced Machine Detection to Voice API
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ For Gradle 3.4 or Higher:

```groovy
dependencies {
implementation 'com.vonage:client:7.4.0'
implementation 'com.vonage:client:7.5.0'
}
```

For older versions:

```groovy
dependencies {
compile 'com.vonage:client:7.4.0'
compile 'com.vonage:client:7.5.0'
}
```

Expand All @@ -54,7 +54,7 @@ Add the following to the correct place in your project's POM file:
<dependency>
<groupId>com.vonage</groupId>
<artifactId>client</artifactId>
<version>7.4.0</version>
<version>7.5.0</version>
</dependency>
```

Expand Down
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ plugins {

group = "com.vonage"
archivesBaseName = "client"
version = "7.4.0"
version = "7.5.0"
sourceCompatibility = "1.8"
targetCompatibility = "1.8"

Expand All @@ -28,8 +28,8 @@ dependencies {

implementation 'commons-codec:commons-codec:1.15'
implementation 'org.apache.httpcomponents:httpclient:4.5.14'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.15.0'
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.15.0'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.15.2'
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.15.2'
implementation 'io.openapitools.jackson.dataformat:jackson-dataformat-hal:1.0.9'
implementation 'com.vonage:jwt:1.0.2'

Expand All @@ -38,7 +38,7 @@ dependencies {
testImplementation 'org.hamcrest:hamcrest-all:1.3'
testImplementation 'org.springframework:spring-test:5.3.27'
testImplementation 'org.springframework:spring-web:5.3.27'
testImplementation 'com.sparkjava:spark-core:2.9.4'
testImplementation 'jakarta.servlet:jakarta.servlet-api:4.0.4'
}

test {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/vonage/client/HttpWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
*/
public class HttpWrapper {
private static final String CLIENT_NAME = "vonage-java-sdk";
private static final String CLIENT_VERSION = "7.4.0";
private static final String CLIENT_VERSION = "7.5.0";
private static final String JAVA_VERSION = System.getProperty("java.version");
private static final String USER_AGENT = String.format("%s/%s java/%s", CLIENT_NAME, CLIENT_VERSION, JAVA_VERSION);

Expand Down
17 changes: 15 additions & 2 deletions src/main/java/com/vonage/client/messages/Channel.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import static com.vonage.client.messages.MessageType.*;
import java.util.EnumSet;
import java.util.Set;
import java.util.stream.Collectors;

/**
* Represents the services available for sending messages.
Expand All @@ -38,15 +39,27 @@ public enum Channel {
}

/**
* This method is useful for determining which message types are supported
* by this messaging service.
* This method is useful for determining which message types are applicable to this messaging service.
*
* @return The Set of message types that this service can handle.
*/
public Set<MessageType> getSupportedMessageTypes() {
return supportedTypes;
}

/**
* Similar to {@link #getSupportedMessageTypes()} but excludes message types used only for inbound / webhooks.
*
* @return The Set of message types that this service can send.
* @since 7.5.0
*/
public Set<MessageType> getSupportedOutboundMessageTypes() {
return getSupportedMessageTypes().stream().filter(mt -> mt != MessageType.UNSUPPORTED &&
mt != MessageType.REPLY && mt != MessageType.ORDER &&
(this != Channel.MMS || mt != MessageType.TEXT)
).collect(Collectors.toSet());
}

@JsonCreator
public static Channel fromString(String value) {
if (value == null) return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public abstract class MessageRequest {
protected MessageRequest(Builder<?, ?> builder, Channel channel, MessageType messageType) {
this.messageType = Objects.requireNonNull(messageType, "Message type cannot be null");
this.channel = Objects.requireNonNull(channel, "Channel cannot be null");
if (!this.channel.getSupportedMessageTypes().contains(this.messageType)) {
if (!this.channel.getSupportedOutboundMessageTypes().contains(this.messageType)) {
throw new IllegalArgumentException(this.messageType +" cannot be sent via "+ this.channel);
}
clientRef = validateClientReference(builder.clientRef);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class VerificationCallback {
protected String clientRef;
protected Integer channelTimeout;
protected List<WorkflowStatus> workflows;
@JsonProperty("action") List<Action> actions;
@JsonProperty("action") Action action;

@JsonIgnoreProperties(ignoreUnknown = true)
static class Action {
Expand Down Expand Up @@ -166,10 +166,10 @@ public List<WorkflowStatus> getWorkflows() {
*/
@JsonIgnore
public URI getSilentAuthUrl() {
if (actions == null || actions.isEmpty() || channel != Channel.SILENT_AUTH) {
if (action == null || channel != Channel.SILENT_AUTH) {
return null;
}
return actions.get(0).checkUrl;
return action.checkUrl;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,22 +132,19 @@ public void testParseSilentAuthUpdate() {
" \"type\": \"event\",\n" +
" \"channel\": \"silent_auth\",\n" +
" \"status\": \"action_pending\",\n" +
" \"action\": [\n" +
" {\n" +
" \"type\": \"check\",\n" +
" \"check_url\": \"https://eu.api.silent.auth/phone_check/v0.1/checks/request_id/redirect\"\n" +
" }\n" +
" ]\n" +
" \"action\": {\n" +
" \"type\": \"check\",\n" +
" \"check_url\": \"https://eu.api.silent.auth/phone_check/v0.1/checks/request_id/redirect\"\n" +
" }\n" +
"}"
);
assertEquals(UUID.fromString("c15236f4-00bf-4b89-84ba-88b25df97315"), webhook.getRequestId());
assertEquals(Instant.ofEpochMilli(1679485739717L), webhook.getTriggeredAt());
assertEquals(CallbackType.EVENT, webhook.getType());
assertEquals(Channel.SILENT_AUTH, webhook.getChannel());
assertEquals(VerificationStatus.ACTION_PENDING, webhook.getStatus());
assertNotNull(webhook.actions);
assertEquals(1, webhook.actions.size());
assertEquals("check", webhook.actions.get(0).type);
assertNotNull(webhook.action);
assertEquals("check", webhook.action.type);
assertEquals(
URI.create("https://eu.api.silent.auth/phone_check/v0.1/checks/request_id/redirect"),
webhook.getSilentAuthUrl()
Expand Down

0 comments on commit db1a4fc

Please sign in to comment.