-
Notifications
You must be signed in to change notification settings - Fork 787
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
Add integrations tests to check malformed API contexts #13234
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -189,6 +189,44 @@ public void createAndPublishGraphQLAPIUsingSchemaWithInterfaces() throws Excepti | |
APIMIntegrationConstants.IS_API_EXISTS); | ||
} | ||
|
||
@Test(groups = { "wso2.am" }, description = | ||
"Attempt GraphQL API creation using a malformed context") | ||
public void testCreateAndPublishGraphQLAPIUsingSchemaWithMalformedContext() throws Exception { | ||
|
||
String schemaDefinitionWithInterface = IOUtils.toString( | ||
getClass().getClassLoader().getResourceAsStream("graphql" + File.separator | ||
+ "schemaWithInterface.graphql"), "UTF-8"); | ||
File file = getTempFileWithContent(schemaDefinitionWithInterface); | ||
GraphQLValidationResponseDTO responseApiDto = restAPIPublisher.validateGraphqlSchemaDefinition(file); | ||
GraphQLValidationResponseGraphQLInfoDTO graphQLInfo = responseApiDto.getGraphQLInfo(); | ||
String arrayToJson = new ObjectMapper().writeValueAsString(graphQLInfo.getOperations()); | ||
JSONArray operations = new JSONArray(arrayToJson); | ||
HttpResponse response = null; | ||
|
||
ArrayList<String> policies = new ArrayList<String>(); | ||
policies.add("Unlimited"); | ||
|
||
JSONObject additionalPropertiesObj = new JSONObject(); | ||
additionalPropertiesObj.put("name", "GraphQLAPIWithInvalidContext"); | ||
additionalPropertiesObj.put("context", "invalidContext{version}"); | ||
additionalPropertiesObj.put("version", API_VERSION_1_0_0); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's move the name, context, version words to constants. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed from a31b2d2 |
||
|
||
JSONObject url = new JSONObject(); | ||
url.put("url", END_POINT_URL); | ||
JSONObject endpointConfig = new JSONObject(); | ||
endpointConfig.put("endpoint_type", "http"); | ||
endpointConfig.put("sandbox_endpoints", url); | ||
endpointConfig.put("production_endpoints", url); | ||
additionalPropertiesObj.put("endpointConfig", endpointConfig); | ||
additionalPropertiesObj.put("policies", policies); | ||
additionalPropertiesObj.put("operations", operations); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can move the property names to constants, as there are multiple usages in the class. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed from a31b2d2 |
||
|
||
// create Graphql API | ||
response = restAPIPublisher.importGraphqlSchemaDefinitionWithInvalidContext(file, additionalPropertiesObj.toString()); | ||
Assert.assertNotNull(response, "Response cannot be null"); | ||
Assert.assertEquals(response.getResponseCode(), 400, "Response Code miss matched when creating the API"); | ||
} | ||
|
||
@Test(groups = {"wso2.am"}, description = "test retrieve schemaDefinition at publisher") | ||
public void testRetrieveSchemaDefinitionAtPublisher() throws Exception { | ||
GraphQLSchemaDTO schema = restAPIPublisher.getGraphqlSchemaDefinition(graphqlAPIId); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -149,6 +149,30 @@ public void testCreateAnAPIThroughThePublisherRest() throws Exception { | |
assertTrue(response.getData().contains("lastUpdatedTimestamp"), "Last Updated Timestamp is not available"); | ||
} | ||
|
||
@Test(groups = { | ||
"wso2.am" }, description = "Create an API Through the Publisher Rest API with malformed context") | ||
public void testCreateAnAPIWithMalformedContextThroughThePublisherRest() | ||
throws Exception { | ||
|
||
// Now APIs with malformed context should not be allowed to create | ||
String apiContextTest = "apim18PublisherTestAPIMalformed`"; | ||
String apiDescription = "This is Test API Created by API Manager Integration Test"; | ||
String apiTag = "tag18-4, tag18-5, tag18-6"; | ||
String apiName = "APIM18PublisherTestMalformed"; | ||
|
||
APIRequest apiCreationRequestBean; | ||
apiCreationRequestBean = new APIRequest(apiName, apiContextTest, new URL(apiProductionEndPointUrl)); | ||
|
||
apiCreationRequestBean.setVersion(apiVersion); | ||
apiCreationRequestBean.setDescription(apiDescription); | ||
apiCreationRequestBean.setTags(apiTag); | ||
apiCreationRequestBean.setTier("Gold"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shall we use APIMIntegrationConstants.API_TIER.GOLD? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed from a31b2d2 |
||
|
||
HttpResponse response = restAPIPublisher.addAPIWithMalformedContext(apiCreationRequestBean); | ||
Assert.assertNotNull(response, "Response cannot be null"); | ||
Assert.assertEquals(response.getResponseCode(), 400, "Response Code miss matched when creating the API"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's use Response.Status.NOT_FOUND.getStatusCode() for 400 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed from a31b2d2 |
||
} | ||
|
||
@Test(groups = {"wso2.am"}, description = "Remove an API Through the Publisher Rest API", | ||
dependsOnMethods = "testCreateAnAPIThroughThePublisherRest") | ||
public void testRemoveAnAPIThroughThePublisherRest() throws Exception { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -101,6 +101,7 @@ enum AUTH_IN { | |
QUERY | ||
} | ||
private final String apiName = "WebSocketAPI"; | ||
private final String apiNameWithMalformedContext = "WebSocketAPIWithMalformedContext"; | ||
private final String applicationName = "WebSocketApplication"; | ||
private final String applicationJWTName = "WebSocketJWTTypeApplication"; | ||
private final String testMessage = "Web Socket Test Message"; | ||
|
@@ -467,6 +468,28 @@ public void testWebSocketAPIInvalidTokenInvocation() throws Exception { | |
} | ||
} | ||
|
||
@Test(description = "Create WebSocket API with malformed context", | ||
dependsOnMethods = "testWebSocketAPIRemoveEndpoint") | ||
public void testCreateWebSocketAPIWithMalformedContext() throws Exception { | ||
|
||
provider = user.getUserName(); | ||
String apiContext = "echo{version}"; | ||
String apiVersion = "1.0.0"; | ||
|
||
URI endpointUri = new URI("ws://" + webSocketServerHost + ":" + webSocketServerPort); | ||
|
||
//Create the api creation request object | ||
apiRequest = new APIRequest(apiNameWithMalformedContext, apiContext, endpointUri, endpointUri); | ||
apiRequest.setVersion(apiVersion); | ||
apiRequest.setTiersCollection(APIMIntegrationConstants.API_TIER.ASYNC_UNLIMITED); | ||
apiRequest.setProvider(provider); | ||
apiRequest.setType("WS"); | ||
apiRequest.setApiTier(APIMIntegrationConstants.API_TIER.UNLIMITED); | ||
|
||
HttpResponse response = restAPIPublisher.addAPIWithMalformedContext(apiRequest); | ||
Assert.assertEquals(response.getResponseCode(), 400, "Response Code miss matched when creating the API"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's use Response.Status.NOT_FOUND.getStatusCode() for 400 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed from a31b2d2 |
||
} | ||
|
||
/** | ||
* Wait for client to receive reply from the server | ||
* | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shall we use APIMIntegrationConstants.API_TIER.UNLIMITED?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed from a31b2d2