Add tests that verify authentication feature 23/106723/13
authorMatej Sramcik <matej.sramcik@pantheon.tech>
Tue, 27 Jun 2023 14:51:14 +0000 (16:51 +0200)
committerIvan Hrasko <ivan.hrasko@pantheon.tech>
Thu, 13 Jul 2023 11:15:04 +0000 (11:15 +0000)
Add tests to  check if securitySchemes and security elements are present.

JIRA: NETCONF-1064
Change-Id: I949ff9ee51cdab607aab88c7e0d208c2ec1b9af7
Signed-off-by: Matej Sramcik <matej.sramcik@pantheon.tech>
restconf/restconf-openapi/src/test/java/org/opendaylight/restconf/openapi/impl/OpenApiGeneratorRFC8040Test.java
restconf/restconf-openapi/src/test/java/org/opendaylight/restconf/openapi/mountpoints/MountPointOpenApiTest.java

index adfef76b219fc34cac9bba9f8e9696480fd1ea7c..3870fe865153b4d19fe5df91eb1aeac9e0bd1fc2 100644 (file)
@@ -419,6 +419,19 @@ public final class OpenApiGeneratorRFC8040Test {
         assertEquals(44, definitions.size());
     }
 
+    /**
+     * Test that checks if securitySchemes and security elements are present.
+     */
+    @Test
+    public void testAuthenticationFeature() {
+        final var module = context.findModule(TOASTER_2, Revision.of(REVISION_DATE)).orElseThrow();
+        final var doc = generator.getOpenApiSpec(module, "http", "localhost:8181", "/", "", context);
+
+        assertEquals("[{\"basicAuth\":[]}]", doc.security().toString());
+        assertEquals("{\"type\":\"http\",\"scheme\":\"basic\"}",
+            doc.components().securitySchemes().basicAuth().toString());
+    }
+
     /**
      *  Test JSON and XML references for request operation.
      */
index e99d79c6e116a656ce9f4cc32919893ff8942424..17e4f7d7a09355fe6b9e68bce7c7697026329bfe 100644 (file)
@@ -251,4 +251,18 @@ public final class MountPointOpenApiTest {
         assertTrue(mountPointApi.paths().containsKey(pathWithoutParameters));
         assertEquals(List.of(), getPathParameters(mountPointApi.paths(), pathWithoutParameters));
     }
+
+    /**
+     * Test that checks if securitySchemes and security elements are present.
+     */
+    @Test
+    public void testAuthenticationFeature() throws Exception {
+        final var mockInfo = DocGenTestHelper.createMockUriInfo(HTTP_URL);
+        openApi.onMountPointCreated(INSTANCE_ID);
+        final var mountPointApi = openApi.getMountPointApi(mockInfo, 1L, Optional.empty());
+
+        assertEquals("[{\"basicAuth\":[]}]", mountPointApi.security().toString());
+        assertEquals("{\"type\":\"http\",\"scheme\":\"basic\"}",
+            mountPointApi.components().securitySchemes().basicAuth().toString());
+    }
 }