[java-idp-plugin-duo] branch main updated: Add paging metadata to Duo admin response mapper.
Phil Smart
philip.smart at jisc.ac.uk
Mon Jan 15 17:24:47 UTC 2024
This is an automated email from the git hooks/post-receive script.
philsmart pushed a commit to branch main
in repository java-idp-plugin-duo.
View the commit online:
http://git.shibboleth.net/view/?p=java-idp-plugin-duo.git;a=commit;h=71a48cc70e7cef32dd8bb5f57e7bc5472bacd1aa
The following commit(s) were added to refs/heads/main by this push:
new 71a48cc7 Add paging metadata to Duo admin response mapper.
71a48cc7 is described below
commit 71a48cc70e7cef32dd8bb5f57e7bc5472bacd1aa
Author: Phil Smart <philip.smart at jisc.ac.uk>
AuthorDate: Mon Jan 15 17:24:44 2024 +0000
Add paging metadata to Duo admin response mapper.
---
.../plugin/authn/duo/DuoAdminResponseWrapper.java | 16 ++++
.../authn/duo/impl/DefaultDuoAdminClientTest.java | 95 ++++++++++++++++++++++
2 files changed, 111 insertions(+)
diff --git a/idp-duo-api/src/main/java/net/shibboleth/idp/plugin/authn/duo/DuoAdminResponseWrapper.java b/idp-duo-api/src/main/java/net/shibboleth/idp/plugin/authn/duo/DuoAdminResponseWrapper.java
index 35c02c7c..097e7611 100644
--- a/idp-duo-api/src/main/java/net/shibboleth/idp/plugin/authn/duo/DuoAdminResponseWrapper.java
+++ b/idp-duo-api/src/main/java/net/shibboleth/idp/plugin/authn/duo/DuoAdminResponseWrapper.java
@@ -14,7 +14,10 @@
package net.shibboleth.idp.plugin.authn.duo;
+import java.util.Map;
+
import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
import com.fasterxml.jackson.annotation.JsonProperty;
@@ -34,6 +37,10 @@ public class DuoAdminResponseWrapper<T> {
@JsonProperty("stat")
private String stat;
+ /** Paging metadata.*/
+ @JsonProperty("metadata")
+ @Nullable private Map<String, Object> metadata;
+
/**
* Get the inner response.
*
@@ -53,5 +60,14 @@ public class DuoAdminResponseWrapper<T> {
assert stat != null;
return stat;
}
+
+ /**
+ * Get the metadata associated with this response.
+ *
+ * @return the metadata.
+ */
+ @Nullable public Map<String, Object> getMetadata() {
+ return metadata;
+ }
}
diff --git a/idp-duo-impl/src/test/java/net/shibboleth/idp/plugin/authn/duo/impl/DefaultDuoAdminClientTest.java b/idp-duo-impl/src/test/java/net/shibboleth/idp/plugin/authn/duo/impl/DefaultDuoAdminClientTest.java
index 867de652..65a1028a 100644
--- a/idp-duo-impl/src/test/java/net/shibboleth/idp/plugin/authn/duo/impl/DefaultDuoAdminClientTest.java
+++ b/idp-duo-impl/src/test/java/net/shibboleth/idp/plugin/authn/duo/impl/DefaultDuoAdminClientTest.java
@@ -16,6 +16,7 @@ package net.shibboleth.idp.plugin.authn.duo.impl;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertNull;
import static org.testng.Assert.fail;
import java.util.List;
@@ -109,6 +110,43 @@ public class DefaultDuoAdminClientTest {
}
""";
+ /** A normal bypass codes response with metadata.*/
+ private static final String GOOD_RESPONSE_BYPASSCODES_WITH_METADATA =
+ """
+ {
+ "response": [
+ {
+ "bypass_code_id": "DB2A9F0012RL54001FA3",
+ "created": 1522260759,
+ "expiration": 1522264359,
+ "reuse_count": 1
+ }
+ ],
+ "stat": "OK",
+ "metadata": {
+ "next_offset": 100,
+ "prev_offset": 0,
+ "total_objects": 951
+ }
+ }
+ """;
+
+ /** A normal bypass codes response with metadata.*/
+ private static final String GOOD_RESPONSE_BYPASSCODES_WITH_NO_METADATA =
+ """
+ {
+ "response": [
+ {
+ "bypass_code_id": "DB2A9F0012RL54001FA3",
+ "created": 1522260759,
+ "expiration": 1522264359,
+ "reuse_count": 1
+ }
+ ],
+ "stat": "OK"
+ }
+ """;
+
/** Two users in response. We require one.*/
private static final String TWO_USER_RESPONSE =
"""
@@ -392,6 +430,63 @@ public class DefaultDuoAdminClientTest {
assertEquals(userWrapper.getResponse().size(), 1);
assertEquals(userWrapper.getResponse().get(0).getUsername(), "jdoe");
}
+
+ @Test
+ public void testClientRetrieve_ByPassCode_OK_WithPagingMetadata() throws Exception {
+ final HttpClient httpClient = Mockito.mock(HttpClient.class);
+ final ClassicHttpResponse httpResponse = Mockito.mock(ClassicHttpResponse.class);
+
+ Mockito.when(httpResponse.getCode()).thenReturn(200);
+ Mockito.when(httpResponse.getEntity()).thenReturn(new StringEntity(GOOD_RESPONSE_BYPASSCODES_WITH_METADATA));
+ Mockito.when(httpClient.executeOpen((HttpHost) Mockito.any(), (ClassicHttpRequest) Mockito.any(),
+ (HttpContext) Mockito.any())).thenReturn(httpResponse);
+
+ client.setHttpClient(httpClient);
+ client.setObjectMapper(new ObjectMapper());
+ client.initialize();
+
+ final DuoAdminResponseWrapper<List<Map<String,Object>>> userWrapper =
+ client.retrieve(new ProfileRequestContext(),"/admin/v1/users/1/bypass_codes", Map.of("username","jdoe"),
+ new TypeReference<DuoAdminResponseWrapper<List<Map<String,Object>>>>() {});
+
+ assertNotNull(userWrapper);
+ assertNotNull(userWrapper.getResponse());
+ assertEquals(userWrapper.getResponse().size(), 1);
+
+ assertNotNull(userWrapper.getMetadata());
+ final var metadata = userWrapper.getMetadata();
+ assert metadata != null;
+ assertEquals(metadata.size(), 3);
+ assertEquals(metadata.get("next_offset"), 100);
+ assertEquals(metadata.get("prev_offset"), 0);
+ assertEquals(metadata.get("total_objects"), 951);
+ }
+
+ @Test
+ public void testClientRetrieve_ByPassCodes_OK_WithoutPagingMetadata() throws Exception {
+ final HttpClient httpClient = Mockito.mock(HttpClient.class);
+ final ClassicHttpResponse httpResponse = Mockito.mock(ClassicHttpResponse.class);
+
+ Mockito.when(httpResponse.getCode()).thenReturn(200);
+ Mockito.when(httpResponse.getEntity()).thenReturn(new StringEntity(GOOD_RESPONSE_BYPASSCODES_WITH_NO_METADATA));
+ Mockito.when(httpClient.executeOpen((HttpHost) Mockito.any(), (ClassicHttpRequest) Mockito.any(),
+ (HttpContext) Mockito.any())).thenReturn(httpResponse);
+
+ client.setHttpClient(httpClient);
+ client.setObjectMapper(new ObjectMapper());
+ client.initialize();
+
+ final DuoAdminResponseWrapper<List<Map<String,Object>>> userWrapper =
+ client.retrieve(new ProfileRequestContext(),"/admin/v1/users/1/bypass_codes", Map.of("username","jdoe"),
+ new TypeReference<DuoAdminResponseWrapper<List<Map<String,Object>>>>() {});
+
+ assertNotNull(userWrapper);
+ assertNotNull(userWrapper.getResponse());
+ assertEquals(userWrapper.getResponse().size(), 1);
+
+ assertNull(userWrapper.getMetadata());
+
+ }
}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list