-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
130 additions
and
0 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
46 changes: 46 additions & 0 deletions
46
src/main/java/org/commonjava/indy/service/ui/models/auth/UserInfo.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,46 @@ | ||
/** | ||
* Copyright (C) 2024 Red Hat, Inc. | ||
* | ||
* Licensed 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 org.commonjava.indy.service.ui.models.auth; | ||
|
||
import org.eclipse.microprofile.openapi.annotations.media.Schema; | ||
|
||
import java.util.Set; | ||
|
||
@Schema( description = "The user information. Contains the user name and user roles" ) | ||
public class UserInfo | ||
{ | ||
@Schema( description = "User name for current user" ) | ||
private final String userName; | ||
|
||
@Schema( description = "User roles for current user" ) | ||
private final Set<String> roles; | ||
|
||
public UserInfo( String userName, Set<String> roles ) | ||
{ | ||
this.userName = userName; | ||
this.roles = roles; | ||
} | ||
|
||
public String getUserName() | ||
{ | ||
return userName; | ||
} | ||
|
||
public Set<String> getRoles() | ||
{ | ||
return roles; | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
src/test/java/org/commonjava/indy/service/ui/jaxrs/auth/AuthResourceTest.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,43 @@ | ||
/** | ||
* Copyright (C) 2024 Red Hat, Inc. | ||
* | ||
* Licensed 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 org.commonjava.indy.service.ui.jaxrs.auth; | ||
|
||
import io.quarkus.test.junit.QuarkusTest; | ||
import io.quarkus.test.security.TestSecurity; | ||
import io.restassured.path.json.JsonPath; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import javax.ws.rs.core.Response; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static org.hamcrest.CoreMatchers.hasItems; | ||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
|
||
@QuarkusTest | ||
public class AuthResourceTest | ||
{ | ||
@TestSecurity( roles = { "power", "admin" }, user = "user" ) | ||
@Test | ||
public void testGetUserInfo() | ||
{ | ||
given().when().get( "/api/admin/auth/userinfo" ).then().statusCode( Response.Status.OK.getStatusCode() ); | ||
final JsonPath resultPath = given().get( "/api/admin/auth/userinfo" ).thenReturn().jsonPath(); | ||
assertThat( resultPath.getString( "userName" ), is( "user" ) ); | ||
assertThat( resultPath.getInt( "roles.size" ), is( 2 ) ); | ||
assertThat( resultPath.getList( "roles" ), hasItems( "power", "admin" ) ); | ||
} | ||
} |