Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integration Tests Implemented for Organization Discovery via Email Domain #20486

Merged
merged 4 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
/*
* Copyright (c) 2019, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
* Copyright (c) 2019-2024, WSO2 LLC. (http://www.wso2.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* WSO2 LLC. licenses this file to you 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.
* 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.wso2.identity.integration.test.rest.api.common;
Expand Down Expand Up @@ -321,6 +323,21 @@ protected Response getResponseOfGetWithQueryParams(String endpointUri, Map<Strin
.get(endpointUri);
}

/**
* Invoke given endpointURL for GET with OAuth2 authentication, using the provided token.
*
* @param endpointURL Endpoint to be invoked.
* @param accessToken OAuth2 access token.
* @return Response.
*/
protected Response getResponseOfGetWithOAuth2(String endpointURL, String accessToken) {

return given().auth().preemptive().oauth2(accessToken)
.contentType(ContentType.JSON)
.when()
.get(endpointURL);
}

/**
* Invoke given endpointUri for GET without authentication.
*
Expand Down Expand Up @@ -388,6 +405,24 @@ protected Response getResponseOfPost(String endpointUri, String body, String con
.post(endpointUri);
}

/**
* Invoke the given endpointURL for POST with the provided body and OAuth2 authentication, using the provided
* access token.
*
* @param endpointURL Endpoint to be invoked.
* @param body Payload.
* @param accessToken OAuth2 access token.
* @return Response.
*/
protected Response getResponseOfPostWithOAuth2(String endpointURL, String body, String accessToken) {

return given().auth().preemptive().oauth2(accessToken)
.contentType(ContentType.JSON)
.body(body)
.when()
.post(endpointURL);
}

/**
* Uploads a file to a given endpointUri with a POST request.
*
Expand Down Expand Up @@ -643,6 +678,24 @@ protected Response getResponseOfPut(String endpointUri, String body, String cont
.put(endpointUri);
}

/**
* Invoke the given endpointURL for PUT with the provided body and OAuth2 authentication, using the provided
* access token.
*
* @param endpointURL Endpoint to be invoked.
* @param body Payload.
* @param accessToken OAuth2 access token.
* @return Response.
*/
protected Response getResponseOfPutWithOAuth2(String endpointURL, String body, String accessToken) {

return given().auth().preemptive().oauth2(accessToken)
.contentType(ContentType.JSON)
.body(body)
.when()
.put(endpointURL);
}

/**
* Invoke given endpointUri for PATCH request with given body, headers and Basic authentication, authentication
* credential being the authenticatingUserName and authenticatingCredential.
Expand Down Expand Up @@ -749,13 +802,28 @@ protected Response getResponseOfDelete(String endpointURI, Map<String, String> h
.delete(endpointURI);
}

/**
* Invoke the given endpointURL for DELETE with OAuth2 authentication, using the provided access token.
*
* @param endpointURL Endpoint to be invoked.
* @param accessToken OAuth2 access token.
* @return Response.
*/
protected Response getResponseOfDeleteWithOAuth2(String endpointURL, String accessToken) {

return given().auth().preemptive().oauth2(accessToken)
.contentType(ContentType.JSON)
.when()
.delete(endpointURL);
}

/**
* Validate the response to be in the following desired format of Error Response
* {
* "code": "some_error_code",
* "message": "Some Error Message",
* "description": "Some Error Description",
* "traceId"" : "corelation-id",
* "traceId"" : "correlation-id",
* }
*
* @param response API error response
Expand All @@ -774,6 +842,29 @@ protected void validateErrorResponse(Response response, int httpStatusCode, Stri
validateErrorDescription(response, errorCode, errorDescriptionArgs);
}

/**
* Validate the response to be in the following desired format of Error Response.
* {
* "code": "some_error_code",
* "message": "Some Error Message",
* "description": "Some Error Description"
* }
*
* @param response API error response.
* @param httpStatusCode HTTP status code.
* @param errorCode Error code.
* @param errorDescriptionArgs Placeholder values if error description in RESTAPIErrors.properties contains
* dynamic values.
*/
protected void validateErrorResponseWithoutTraceId(Response response, int httpStatusCode, String errorCode,
String... errorDescriptionArgs) {

validateHttpStatusCode(response, httpStatusCode);
validateResponseElement(response, "code", is(errorCode));
validateErrorMessage(response, errorCode);
validateErrorDescription(response, errorCode, errorDescriptionArgs);
}

/**
* Validate http status code of the response
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com).
* Copyright (c) 2023-2024, WSO2 LLC. (http://www.wso2.com).
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
Expand All @@ -15,6 +15,7 @@
* specific language governing permissions and limitations
* under the License.
*/

package org.wso2.identity.integration.test.rest.api.server.organization.management.v1;

import io.restassured.RestAssured;
Expand All @@ -39,6 +40,8 @@ public class OrganizationManagementBaseTest extends RESTAPIServerTestBase {
static final String API_VERSION = "v1";

static final String ORGANIZATION_MANAGEMENT_API_BASE_PATH = "/organizations";
static final String ORGANIZATION_CONFIGS_API_BASE_PATH = "/organization-configs";
static final String ORGANIZATION_DISCOVERY_API_PATH = "/discovery";
static final String PATH_SEPARATOR = "/";

protected static String swaggerDefinition;
Expand Down
Loading