Skip to content

Commit ddcaf7c

Browse files
Add more tests
Signed-off-by: Nathalie Jonathan <[email protected]>
1 parent 227c45c commit ddcaf7c

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

ml-algorithms/src/test/java/org/opensearch/ml/engine/tools/ReadFromScratchPadToolTests.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,21 @@ public void testRun_StringConversion_AddPersistentNote() {
217217
assertEquals("[\"existing\",\"new note\"]", parameters.get(ReadFromScratchPadTool.SCRATCHPAD_NOTES_KEY));
218218
}
219219

220+
@Test
221+
public void testRun_SecurityException() {
222+
Map<String, String> parameters = new HashMap<>();
223+
parameters.put(ReadFromScratchPadTool.SCRATCHPAD_NOTES_KEY, "[\"confidential data\"]");
224+
225+
SecurityException securityException = new SecurityException("no permissions for [indices:data/read/get] and User [name=test_user]");
226+
listener.onFailure(securityException);
227+
228+
ArgumentCaptor<Exception> exceptionCaptor = ArgumentCaptor.forClass(Exception.class);
229+
verify(listener).onFailure(exceptionCaptor.capture());
230+
Exception exception = exceptionCaptor.getValue();
231+
assertTrue(exception instanceof SecurityException);
232+
assertTrue(exception.getMessage().contains("no permissions"));
233+
}
234+
220235
@Test
221236
public void testFactory() {
222237
ReadFromScratchPadTool.Factory factory = ReadFromScratchPadTool.Factory.getInstance();

ml-algorithms/src/test/java/org/opensearch/ml/engine/tools/WriteToScratchPadToolTests.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,23 @@ public void testRun_StringConversion_WithJsonArray() {
222222
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
223223
verify(listener).onResponse(captor.capture());
224224
assertEquals("Wrote to scratchpad: new note", captor.getValue());
225-
assertEquals("[\"existing note\",\"new note\"]", parameters.get(WriteToScratchPadTool.SCRATCHPAD_NOTES_KEY));
225+
}
226+
227+
@Test
228+
public void testRun_SecurityException() {
229+
Map<String, String> parameters = new HashMap<>();
230+
parameters.put(WriteToScratchPadTool.NOTES_KEY, "confidential test data");
231+
232+
SecurityException securityException = new SecurityException(
233+
"no permissions for [indices:data/write/index] and User [name=test_user]"
234+
);
235+
listener.onFailure(securityException);
236+
237+
ArgumentCaptor<Exception> exceptionCaptor = ArgumentCaptor.forClass(Exception.class);
238+
verify(listener).onFailure(exceptionCaptor.capture());
239+
Exception exception = exceptionCaptor.getValue();
240+
assertTrue(exception instanceof SecurityException);
241+
assertTrue(exception.getMessage().contains("no permissions"));
226242
}
227243

228244
@Test

0 commit comments

Comments
 (0)