[java-oidc-common] branch main updated: Add OIDC Provider Metadata Parsing Strategy test

Phil Smart philip.smart at jisc.ac.uk
Wed Feb 23 17:17:03 UTC 2022


This is an automated email from the git hooks/post-receive script.

philsmart pushed a commit to branch main
in repository java-oidc-common.

View the commit online:
http://git.shibboleth.net/view/?p=java-oidc-common.git;a=commit;h=370420199f537dedb8d26b07809f8fde24455306

The following commit(s) were added to refs/heads/main by this push:
     new 3704201  Add OIDC Provider Metadata Parsing Strategy test
3704201 is described below

commit 370420199f537dedb8d26b07809f8fde24455306
Author: Phil Smart <philip.smart at jisc.ac.uk>
AuthorDate: Wed Feb 23 17:16:54 2022 +0000

    Add OIDC Provider Metadata Parsing Strategy test
---
 ...ultOIDCProviderMetadataParsingStrategyTest.java | 69 ++++++++++++++++++++++
 1 file changed, 69 insertions(+)

diff --git a/oidc-common-metadata-impl/src/test/java/net/shibboleth/oidc/metadata/cache/impl/DefaultOIDCProviderMetadataParsingStrategyTest.java b/oidc-common-metadata-impl/src/test/java/net/shibboleth/oidc/metadata/cache/impl/DefaultOIDCProviderMetadataParsingStrategyTest.java
new file mode 100644
index 0000000..9b836dc
--- /dev/null
+++ b/oidc-common-metadata-impl/src/test/java/net/shibboleth/oidc/metadata/cache/impl/DefaultOIDCProviderMetadataParsingStrategyTest.java
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the University Corporation for Advanced Internet Development,
+ * Inc. (UCAID) under one or more contributor license agreements.  See the
+ * NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The UCAID licenses this file to You under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file except in
+ * compliance with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.shibboleth.oidc.metadata.cache.impl;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.util.List;
+
+import org.springframework.core.io.ClassPathResource;
+import org.testng.annotations.Test;
+
+import com.google.common.io.ByteStreams;
+import com.nimbusds.openid.connect.sdk.op.OIDCProviderMetadata;
+
+/** Test for {@link DefaultOIDCProviderMetadataParsingStrategy}.*/
+public class DefaultOIDCProviderMetadataParsingStrategyTest {
+    
+    @Test
+    public void testParsing_Success() throws IOException {
+        final var strategy = new DefaultOIDCProviderMetadataParsingStrategy();
+        
+        final var metadata = 
+                new ClassPathResource("/net/shibboleth/oidc/metadata/impl/openid-configuration.json");
+        final var metadataAsBytes = ByteStreams.toByteArray(metadata.getInputStream());
+        
+        final List<OIDCProviderMetadata> metadataParsed = strategy.apply(metadataAsBytes);
+        assertNotNull(metadataParsed);
+        assertEquals(metadataParsed.size(), 1);
+    }
+    
+    @Test
+    public void testParsing_BadJson_Fail() throws IOException {
+        final var strategy = new DefaultOIDCProviderMetadataParsingStrategy();
+
+        final var metadataAsBytes = "bad json".getBytes(StandardCharsets.UTF_8);
+        
+        final List<OIDCProviderMetadata> metadataParsed = strategy.apply(metadataAsBytes);
+        assertNotNull(metadataParsed);
+        assertEquals(metadataParsed.size(), 0);
+    }
+    
+    @Test
+    public void testParsing_NullBytes_Success() throws IOException {
+        final var strategy = new DefaultOIDCProviderMetadataParsingStrategy();
+        
+        final List<OIDCProviderMetadata> metadataParsed = strategy.apply(null);
+        assertNotNull(metadataParsed);
+        assertEquals(metadataParsed.size(), 0);
+    }
+
+}

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list