1 package org.apache.archiva.rest.services.v2;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
21 import io.restassured.response.Response;
22 import org.apache.archiva.components.rest.model.PagedResult;
23 import org.apache.archiva.components.rest.model.PropertyEntry;
24 import org.apache.archiva.rest.api.model.v2.BeanInformation;
25 import org.junit.jupiter.api.AfterAll;
26 import org.junit.jupiter.api.BeforeAll;
27 import org.junit.jupiter.api.DisplayName;
28 import org.junit.jupiter.api.MethodOrderer;
29 import org.junit.jupiter.api.Tag;
30 import org.junit.jupiter.api.Test;
31 import org.junit.jupiter.api.TestInstance;
32 import org.junit.jupiter.api.TestMethodOrder;
33 import org.junit.jupiter.api.extension.ExtendWith;
34 import org.springframework.test.context.ContextConfiguration;
35 import org.springframework.test.context.junit.jupiter.SpringExtension;
37 import java.util.List;
39 import static io.restassured.RestAssured.given;
40 import static io.restassured.http.ContentType.JSON;
41 import static org.junit.jupiter.api.Assertions.*;
44 * @author Martin Stockhammer <martin_s@apache.org>
46 @TestInstance( TestInstance.Lifecycle.PER_CLASS )
48 @TestMethodOrder( MethodOrderer.Random.class )
49 @DisplayName( "Native REST tests for V2 SecurityConfigurationService" )
50 public class NativeSecurityConfigurationServiceTest extends AbstractNativeRestServices
53 protected String getServicePath( )
59 void setup( ) throws Exception
65 void destroy( ) throws Exception
67 super.shutdownNative( );
71 void testGetConfiguration() {
72 String token = getAdminToken( );
73 Response response = given( ).spec( getRequestSpec( token ) ).contentType( JSON )
76 .then( ).statusCode( 200 ).extract( ).response( );
77 assertNotNull( response );
78 assertEquals( "jpa", response.getBody( ).jsonPath( ).getString( "active_user_managers[0]" ) );
79 assertEquals( "jpa", response.getBody( ).jsonPath( ).getString( "active_rbac_managers[0]" ) );
80 assertEquals( "memory", response.getBody( ).jsonPath( ).getString( "properties.\"authentication.jwt.keystoreType\"" ) );
81 assertEquals("10",response.getBody( ).jsonPath( ).getString( "properties.\"security.policy.allowed.login.attempt\""));
82 assertTrue( response.getBody( ).jsonPath( ).getBoolean( "user_cache_enabled" ) );
83 assertFalse( response.getBody( ).jsonPath( ).getBoolean( "ldap_active" ) );
87 void testGetConfigurationProperties() {
88 String token = getAdminToken( );
89 Response response = given( ).spec( getRequestSpec( token ) ).contentType( JSON )
91 .get( "config/properties" )
92 .then( ).statusCode( 200 ).extract( ).response( );
93 assertNotNull( response );
94 PagedResult<PropertyEntry> result = response.getBody( ).jsonPath( ).getObject( "", PagedResult.class );
95 List<PropertyEntry> propList = response.getBody( ).jsonPath( ).getList( "data", PropertyEntry.class );
96 assertEquals( 10, result.getPagination( ).getLimit( ) );
97 assertEquals( 0, result.getPagination( ).getOffset( ) );
98 assertEquals( 47, result.getPagination( ).getTotalCount( ) );
99 assertEquals( "authentication.jwt.keystoreType", propList.get( 0 ).getKey() );
101 response = given( ).spec( getRequestSpec( token ) ).contentType( JSON )
103 .queryParam( "offset", "3" )
104 .queryParam( "limit", "5" )
105 .get( "config/properties" )
106 .then( ).statusCode( 200 ).extract( ).response( );
108 assertNotNull( response );
109 result = response.getBody( ).jsonPath( ).getObject( "", PagedResult.class );
110 assertEquals( 5, result.getPagination( ).getLimit( ) );
111 assertEquals( 47, result.getPagination( ).getTotalCount( ) );
112 propList = response.getBody( ).jsonPath( ).getList( "data", PropertyEntry.class );
113 assertEquals( "authentication.jwt.refreshLifetimeMs", propList.get( 0 ).getKey() );
117 void testGetLdapConfiguration() {
118 String token = getAdminToken( );
119 Response response = given( ).spec( getRequestSpec( token ) ).contentType( JSON )
121 .get( "config/ldap" )
122 .then( ).statusCode( 200 ).extract( ).response( );
123 assertNotNull( response );
124 assertEquals( "", response.getBody( ).jsonPath( ).get( "host_name" ) );
125 assertEquals( 13, response.getBody( ).jsonPath( ).getMap( "properties" ).size( ) );
129 void testGetCacheConfiguration() {
130 String token = getAdminToken( );
131 Response response = given( ).spec( getRequestSpec( token ) ).contentType( JSON )
133 .get( "config/cache" )
134 .then( ).statusCode( 200 ).extract( ).response( );
135 assertNotNull( response );
139 void testGetUserManagers() {
140 String token = getAdminToken( );
141 Response response = given( ).spec( getRequestSpec( token ) ).contentType( JSON )
143 .get( "user_managers" )
145 .then( ).statusCode( 200 ).extract( ).response( );
146 assertNotNull( response );
147 List<BeanInformation> usrList = response.getBody( ).jsonPath( ).getList( "", BeanInformation.class );
148 assertEquals( 2, usrList.size( ) );
149 assertTrue( usrList.stream( ).anyMatch( bi -> "LDAP User Manager".equals( bi.getDisplayName( ) ) ) );
150 assertTrue( usrList.stream( ).anyMatch( bi -> "Database User Manager".equals( bi.getDisplayName( ) ) ) );
154 void testGetRbacManagers() {
155 String token = getAdminToken( );
156 Response response = given( ).spec( getRequestSpec( token ) ).contentType( JSON )
158 .get( "rbac_managers" )
160 .then( ).statusCode( 200 ).extract( ).response( );
161 assertNotNull( response );
162 List<BeanInformation> rbacList = response.getBody( ).jsonPath( ).getList( "", BeanInformation.class );
163 assertEquals( 2, rbacList.size( ) );
164 assertTrue( rbacList.stream( ).anyMatch( bi -> "Database RBAC Manager".equals( bi.getDisplayName( ) ) ) );
165 assertTrue( rbacList.stream( ).anyMatch( bi -> "LDAP RBAC Manager".equals( bi.getDisplayName( ) ) ) );