24
24
import org .springframework .http .MediaType ;
25
25
import org .zowe .apiml .util .TestWithStartedInstances ;
26
26
import org .zowe .apiml .util .categories .CatalogTest ;
27
- import org .zowe .apiml .util .config .*;
28
- import org .zowe .apiml .util .http .*;
27
+ import org .zowe .apiml .util .config .ConfigReader ;
28
+ import org .zowe .apiml .util .config .GatewayServiceConfiguration ;
29
+ import org .zowe .apiml .util .config .SslContext ;
30
+ import org .zowe .apiml .util .http .HttpClientUtils ;
31
+ import org .zowe .apiml .util .http .HttpRequestUtils ;
32
+ import org .zowe .apiml .util .http .HttpSecurityUtils ;
29
33
30
34
import java .io .IOException ;
31
35
import java .net .URI ;
@@ -51,6 +55,11 @@ class ApiCatalogEndpointIntegrationTest implements TestWithStartedInstances {
51
55
private static final String GET_API_CATALOG_API_DOC_ENDPOINT = "/apicatalog/api/v1/apidoc/apicatalog/v1" ;
52
56
private static final String INVALID_API_CATALOG_API_DOC_ENDPOINT = "/apicatalog/api/v1/apidoc/apicatalog/v2" ;
53
57
58
+ private final static String UNAUTHORIZED_USERNAME = ConfigReader .environmentConfiguration ().getAuxiliaryUserList ().getCredentials ("servicesinfo-unauthorized" ).get (0 ).getUser ();
59
+ private final static String UNAUTHORIZED_PASSWORD = ConfigReader .environmentConfiguration ().getAuxiliaryUserList ().getCredentials ("servicesinfo-unauthorized" ).get (0 ).getPassword ();
60
+ private final static String USERNAME = ConfigReader .environmentConfiguration ().getAuxiliaryUserList ().getCredentials ("servicesinfo-authorized" ).get (0 ).getUser ();
61
+ private final static String PASSWORD = ConfigReader .environmentConfiguration ().getAuxiliaryUserList ().getCredentials ("servicesinfo-authorized" ).get (0 ).getPassword ();
62
+
54
63
private String baseHost ;
55
64
56
65
@ BeforeEach
@@ -169,23 +178,30 @@ void cleanupStaticDefinition() {
169
178
@ Test
170
179
@ Order (1 )
171
180
void whenCallStaticApiRefresh_thenResponseOk () throws IOException {
172
- getStaticApiResponse (REFRESH_STATIC_APIS_ENDPOINT , null , HttpStatus .SC_OK , null );
181
+ getStaticApiResponse (REFRESH_STATIC_APIS_ENDPOINT , null , HttpStatus .SC_OK , null , gatewayToken ( USERNAME , PASSWORD ) );
173
182
}
174
183
175
184
@ Test
176
185
@ Order (30 )
177
186
void whenCallStaticDefinitionGenerate_thenResponse201 () throws IOException {
178
187
String json = "# Dummy content" ;
179
- getStaticApiResponse (STATIC_DEFINITION_GENERATE_ENDPOINT , staticDefinitionServiceId ,HttpStatus .SC_CREATED , json );
188
+ getStaticApiResponse (STATIC_DEFINITION_GENERATE_ENDPOINT , staticDefinitionServiceId , HttpStatus .SC_CREATED , json , gatewayToken (USERNAME , PASSWORD ));
189
+ }
190
+
191
+ @ Test
192
+ @ Order (31 )
193
+ void whenCallStaticDefinitionGenerateWithUnauthorizedUser_thenResponse403 () throws IOException {
194
+ String json = "# Dummy content" ;
195
+ getStaticApiResponse (STATIC_DEFINITION_GENERATE_ENDPOINT , staticDefinitionServiceId , HttpStatus .SC_FORBIDDEN , json , gatewayToken (UNAUTHORIZED_USERNAME , UNAUTHORIZED_PASSWORD ));
180
196
}
181
197
182
- private Response getStaticApiResponse (String endpoint , String definitionFileName , int returnCode , String body ) throws IOException {
198
+ private Response getStaticApiResponse (String endpoint , String definitionFileName , int returnCode , String body , String JWT ) throws IOException {
183
199
URI uri = getUriFromGateway (endpoint );
184
200
RestAssured .enableLoggingOfRequestAndResponseIfValidationFails ();
185
201
186
202
RequestSpecification requestSpecification = given ().config (SslContext .tlsWithoutCert ).relaxedHTTPSValidation ()
187
203
.when ()
188
- .cookie (COOKIE_NAME , gatewayToken () )
204
+ .cookie (COOKIE_NAME , JWT )
189
205
.header ("Accept" , MediaType .APPLICATION_JSON_VALUE );
190
206
if (body != null ) {
191
207
requestSpecification
0 commit comments