-
Notifications
You must be signed in to change notification settings - Fork 131
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
removing api keys from the integ test log #3112
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,8 +17,10 @@ | |
import org.junit.Before; | ||
import org.junit.Ignore; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.ExpectedException; | ||
import org.opensearch.client.Response; | ||
import org.opensearch.client.ResponseException; | ||
import org.opensearch.ml.common.MLTaskState; | ||
import org.opensearch.ml.utils.TestHelper; | ||
|
||
|
@@ -76,39 +78,63 @@ public void setup() throws IOException, InterruptedException { | |
Thread.sleep(20000); | ||
} | ||
|
||
public void testCreateConnector() throws IOException { | ||
Response response = createConnector(completionModelConnectorEntity); | ||
Map responseMap = parseResponseToMap(response); | ||
assertNotNull((String) responseMap.get("connector_id")); | ||
} | ||
|
||
public void testGetConnector() throws IOException { | ||
public void testCreate_Get_DeleteConnector() throws IOException { | ||
Response response = createConnector(completionModelConnectorEntity); | ||
Map responseMap = parseResponseToMap(response); | ||
String connectorId = (String) responseMap.get("connector_id"); | ||
assertNotNull(connectorId); // Testing create connector | ||
|
||
// Testing Get connector | ||
response = TestHelper.makeRequest(client(), "GET", "/_plugins/_ml/connectors/" + connectorId, null, "", null); | ||
responseMap = parseResponseToMap(response); | ||
assertEquals("OpenAI Connector", (String) responseMap.get("name")); | ||
assertEquals("1", (String) responseMap.get("version")); | ||
assertEquals("The connector to public OpenAI model service for GPT 3.5", (String) responseMap.get("description")); | ||
assertEquals("http", (String) responseMap.get("protocol")); | ||
} | ||
assertEquals("OpenAI Connector", responseMap.get("name")); | ||
assertEquals("1", responseMap.get("version")); | ||
assertEquals("The connector to public OpenAI model service for GPT 3.5", responseMap.get("description")); | ||
assertEquals("http", responseMap.get("protocol")); | ||
|
||
public void testDeleteConnector() throws IOException { | ||
Response response = createConnector(completionModelConnectorEntity); | ||
Map responseMap = parseResponseToMap(response); | ||
String connectorId = (String) responseMap.get("connector_id"); | ||
// Testing delete connector | ||
response = TestHelper.makeRequest(client(), "DELETE", "/_plugins/_ml/connectors/" + connectorId, null, "", null); | ||
responseMap = parseResponseToMap(response); | ||
assertEquals("deleted", (String) responseMap.get("result")); | ||
assertEquals("deleted", responseMap.get("result")); | ||
|
||
} | ||
|
||
private static String maskSensitiveInfo(String input) { | ||
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. minor: can add a simple test case for this |
||
// Regex to remove the whole credential object and replace it with "***" | ||
String regex = "\"credential\":\\{.*?}"; | ||
return input.replaceAll(regex, "\"credential\": \"***\""); | ||
} | ||
|
||
@Test | ||
public void testMaskSensitiveInfo_withCredential() { | ||
String input = "{\"credential\":{\"username\":\"admin\",\"password\":\"secret\"}}"; | ||
String expectedOutput = "{\"credential\": \"***\"}"; | ||
String actualOutput = maskSensitiveInfo(input); | ||
assertEquals(expectedOutput, actualOutput); | ||
} | ||
|
||
@Test | ||
public void testMaskSensitiveInfo_noCredential() { | ||
String input = "{\"otherInfo\":\"someValue\"}"; | ||
String expectedOutput = "{\"otherInfo\":\"someValue\"}"; | ||
String actualOutput = maskSensitiveInfo(input); | ||
assertEquals(expectedOutput, actualOutput); | ||
} | ||
|
||
@Test | ||
public void testMaskSensitiveInfo_emptyInput() { | ||
String input = ""; | ||
String expectedOutput = ""; | ||
String actualOutput = maskSensitiveInfo(input); | ||
assertEquals(expectedOutput, actualOutput); | ||
} | ||
|
||
public void testSearchConnectors_beforeCreation() throws IOException { | ||
String searchEntity = "{\n" + " \"query\": {\n" + " \"match_all\": {}\n" + " },\n" + " \"size\": 1000\n" + "}"; | ||
Response response = TestHelper | ||
.makeRequest(client(), "GET", "/_plugins/_ml/connectors/_search", null, TestHelper.toHttpEntity(searchEntity), null); | ||
Map responseMap = parseResponseToMap(response); | ||
assertEquals((Double) 0.0, (Double) ((Map) ((Map) responseMap.get("hits")).get("total")).get("value")); | ||
assertEquals(0.0, ((Map) ((Map) responseMap.get("hits")).get("total")).get("value")); | ||
} | ||
|
||
public void testSearchConnectors_afterCreation() throws IOException { | ||
|
@@ -125,7 +151,7 @@ public void testSearchRemoteModels_beforeCreation() throws IOException { | |
Response response = TestHelper | ||
.makeRequest(client(), "GET", "/_plugins/_ml/models/_search", null, TestHelper.toHttpEntity(searchEntity), null); | ||
Map responseMap = parseResponseToMap(response); | ||
assertEquals((Double) 0.0, (Double) ((Map) ((Map) responseMap.get("hits")).get("total")).get("value")); | ||
assertEquals(0.0, ((Map) ((Map) responseMap.get("hits")).get("total")).get("value")); | ||
} | ||
|
||
public void testSearchRemoteModels_afterCreation() throws IOException { | ||
|
@@ -134,15 +160,15 @@ public void testSearchRemoteModels_afterCreation() throws IOException { | |
Response response = TestHelper | ||
.makeRequest(client(), "GET", "/_plugins/_ml/models/_search", null, TestHelper.toHttpEntity(searchEntity), null); | ||
Map responseMap = parseResponseToMap(response); | ||
assertEquals((Double) 1.0, (Double) ((Map) ((Map) responseMap.get("hits")).get("total")).get("value")); | ||
assertEquals(1.0, ((Map) ((Map) responseMap.get("hits")).get("total")).get("value")); | ||
} | ||
|
||
public void testSearchModelGroups_beforeCreation() throws IOException { | ||
String searchEntity = "{\n" + " \"query\": {\n" + " \"match_all\": {}\n" + " },\n" + " \"size\": 1000\n" + "}"; | ||
Response response = TestHelper | ||
.makeRequest(client(), "GET", "/_plugins/_ml/model_groups/_search", null, TestHelper.toHttpEntity(searchEntity), null); | ||
Map responseMap = parseResponseToMap(response); | ||
assertEquals((Double) 0.0, (Double) ((Map) ((Map) responseMap.get("hits")).get("total")).get("value")); | ||
assertEquals(0.0, ((Map) ((Map) responseMap.get("hits")).get("total")).get("value")); | ||
} | ||
|
||
public void testSearchModelGroups_afterCreation() throws IOException { | ||
|
@@ -151,15 +177,15 @@ public void testSearchModelGroups_afterCreation() throws IOException { | |
Response response = TestHelper | ||
.makeRequest(client(), "GET", "/_plugins/_ml/model_groups/_search", null, TestHelper.toHttpEntity(searchEntity), null); | ||
Map responseMap = parseResponseToMap(response); | ||
assertEquals((Double) 1.0, (Double) ((Map) ((Map) responseMap.get("hits")).get("total")).get("value")); | ||
assertEquals(1.0, ((Map) ((Map) responseMap.get("hits")).get("total")).get("value")); | ||
} | ||
|
||
public void testSearchMLTasks_beforeCreation() throws IOException { | ||
String searchEntity = "{\n" + " \"query\": {\n" + " \"match_all\": {}\n" + " },\n" + " \"size\": 1000\n" + "}"; | ||
Response response = TestHelper | ||
.makeRequest(client(), "GET", "/_plugins/_ml/tasks/_search", null, TestHelper.toHttpEntity(searchEntity), null); | ||
Map responseMap = parseResponseToMap(response); | ||
assertEquals((Double) 0.0, (Double) ((Map) ((Map) responseMap.get("hits")).get("total")).get("value")); | ||
assertEquals(0.0, ((Map) ((Map) responseMap.get("hits")).get("total")).get("value")); | ||
} | ||
|
||
public void testSearchMLTasks_afterCreation() throws IOException { | ||
|
@@ -169,7 +195,7 @@ public void testSearchMLTasks_afterCreation() throws IOException { | |
Response response = TestHelper | ||
.makeRequest(client(), "GET", "/_plugins/_ml/tasks/_search", null, TestHelper.toHttpEntity(searchEntity), null); | ||
Map responseMap = parseResponseToMap(response); | ||
assertEquals((Double) 1.0, (Double) ((Map) ((Map) responseMap.get("hits")).get("total")).get("value")); | ||
assertEquals(1.0, ((Map) ((Map) responseMap.get("hits")).get("total")).get("value")); | ||
} | ||
|
||
public void testDeployRemoteModel() throws IOException, InterruptedException { | ||
|
@@ -185,7 +211,7 @@ public void testDeployRemoteModel() throws IOException, InterruptedException { | |
String modelId = (String) responseMap.get("model_id"); | ||
response = deployRemoteModel(modelId); | ||
responseMap = parseResponseToMap(response); | ||
assertEquals("COMPLETED", (String) responseMap.get("status")); | ||
assertEquals("COMPLETED", responseMap.get("status")); | ||
taskId = (String) responseMap.get("task_id"); | ||
waitForTask(taskId, MLTaskState.COMPLETED); | ||
} | ||
|
@@ -838,7 +864,12 @@ public void testCohereClassifyModel() throws IOException, InterruptedException { | |
} | ||
|
||
public static Response createConnector(String input) throws IOException { | ||
return TestHelper.makeRequest(client(), "POST", "/_plugins/_ml/connectors/_create", null, TestHelper.toHttpEntity(input), null); | ||
try { | ||
return TestHelper.makeRequest(client(), "POST", "/_plugins/_ml/connectors/_create", null, TestHelper.toHttpEntity(input), null); | ||
} catch (ResponseException e) { | ||
String sanitizedMessage = maskSensitiveInfo(e.getMessage());// Log sanitized message | ||
throw new RuntimeException("Request failed: " + sanitizedMessage); // Re-throw sanitized exception | ||
} | ||
} | ||
|
||
public static Response registerRemoteModel(String name, String connectorId) throws IOException { | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
since we have combined the 3 api calls, does the error message give enough information to validate at which step (create, get, delete) the test failed?
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.
If any assertion fails, it will indicate which assertion is failing within the method, correct? I’ve noticed a lot of redundant resource creation in this integration test class, which I plan to remove step by step. In this case, we are now creating the connector resource once and reusing it for three tests, rather than creating the resource three separate times.
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.
Makes sense, i misunderstood the change - assumed it was a connection test to the connector itself during creation phase via API and not integ tests. Thanks for clearing this up!