-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OpenAPI: remove check that avoids running auto-security at build
Signed-off-by: Michael Edgar <[email protected]>
- Loading branch information
Showing
4 changed files
with
100 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...o/quarkus/smallrye/openapi/test/jaxrs/AutoSecurityRolesAllowedWithScopesOIDCTestCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package io.quarkus.smallrye.openapi.test.jaxrs; | ||
|
||
import java.util.List; | ||
|
||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.builder.Version; | ||
import io.quarkus.maven.dependency.Dependency; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
class AutoSecurityRolesAllowedWithScopesOIDCTestCase extends AutoSecurityRolesAllowedWithScopesTestBase { | ||
|
||
@RegisterExtension | ||
static QuarkusUnitTest runner = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar | ||
.addClasses(ResourceBean.class, OpenApiResourceSecuredAtClassLevel.class, | ||
OpenApiResourceSecuredAtMethodLevel.class, OpenApiResourceSecuredAtMethodLevel2.class) | ||
.addAsResource( | ||
new StringAsset( | ||
"quarkus.smallrye-openapi.security-scheme-name=MyScheme\n" | ||
+ "quarkus.smallrye-openapi.security-scheme-description=Authentication using MyScheme\n" | ||
+ "quarkus.devservices.enabled=false\n" | ||
+ "quarkus.oidc.auth-server-url=http://localhost:8081/auth/realms/OpenAPIOIDC"), | ||
"application.properties")) | ||
.setForcedDependencies(List.of( | ||
Dependency.of("io.quarkus", "quarkus-oidc", Version.getVersion()))); | ||
|
||
@Test | ||
void testAutoSecurityRequirement() { | ||
testAutoSecurityRequirement("openIdConnect"); | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
...va/io/quarkus/smallrye/openapi/test/jaxrs/AutoSecurityRolesAllowedWithScopesTestBase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package io.quarkus.smallrye.openapi.test.jaxrs; | ||
|
||
import static org.hamcrest.Matchers.aMapWithSize; | ||
import static org.hamcrest.Matchers.allOf; | ||
import static org.hamcrest.Matchers.contains; | ||
import static org.hamcrest.Matchers.emptyIterable; | ||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.hamcrest.Matchers.hasEntry; | ||
import static org.hamcrest.Matchers.hasItem; | ||
import static org.hamcrest.Matchers.iterableWithSize; | ||
import static org.hamcrest.Matchers.nullValue; | ||
|
||
import org.hamcrest.Matcher; | ||
|
||
import io.restassured.RestAssured; | ||
|
||
abstract class AutoSecurityRolesAllowedWithScopesTestBase { | ||
|
||
static Matcher<Iterable<Object>> schemeArray(String schemeName, Matcher<Iterable<?>> scopesMatcher) { | ||
return allOf( | ||
iterableWithSize(1), | ||
hasItem(allOf( | ||
aMapWithSize(1), | ||
hasEntry(equalTo(schemeName), scopesMatcher)))); | ||
} | ||
|
||
void testAutoSecurityRequirement(String schemeType) { | ||
RestAssured.given() | ||
.header("Accept", "application/json") | ||
.when() | ||
.get("/q/openapi") | ||
.then() | ||
.log().body() | ||
.and() | ||
.body("components.securitySchemes.MyScheme", allOf( | ||
hasEntry("type", schemeType), | ||
hasEntry("description", "Authentication using MyScheme"))) | ||
.and() | ||
// OpenApiResourceSecuredAtMethodLevel | ||
.body("paths.'/resource2/test-security/naked'.get.security", schemeArray("MyScheme", contains("admin"))) | ||
.body("paths.'/resource2/test-security/annotated'.get.security", | ||
schemeArray("JWTCompanyAuthentication", emptyIterable())) | ||
.body("paths.'/resource2/test-security/methodLevel/1'.get.security", schemeArray("MyScheme", contains("user1"))) | ||
.body("paths.'/resource2/test-security/methodLevel/2'.get.security", schemeArray("MyScheme", contains("user2"))) | ||
.body("paths.'/resource2/test-security/methodLevel/public'.get.security", nullValue()) | ||
.body("paths.'/resource2/test-security/annotated/documented'.get.security", | ||
schemeArray("JWTCompanyAuthentication", emptyIterable())) | ||
.body("paths.'/resource2/test-security/methodLevel/3'.get.security", schemeArray("MyScheme", contains("admin"))) | ||
.and() | ||
// OpenApiResourceSecuredAtClassLevel | ||
.body("paths.'/resource2/test-security/classLevel/1'.get.security", schemeArray("MyScheme", contains("user1"))) | ||
.body("paths.'/resource2/test-security/classLevel/2'.get.security", schemeArray("MyScheme", contains("user2"))) | ||
.body("paths.'/resource2/test-security/classLevel/3'.get.security", schemeArray("MyOwnName", emptyIterable())) | ||
.body("paths.'/resource2/test-security/classLevel/4'.get.security", schemeArray("MyScheme", contains("admin"))) | ||
.and() | ||
// OpenApiResourceSecuredAtMethodLevel2 | ||
.body("paths.'/resource3/test-security/annotated'.get.security", | ||
schemeArray("AtClassLevel", emptyIterable())); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters