Skip to content

Commit e09d6cb

Browse files
authored
[ZEPPELIN-5826] Activate credentialReplacement test (#4468)
1 parent 73f9650 commit e09d6cb

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/ParagraphTest.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,15 @@
2222
import static org.junit.Assert.assertNotEquals;
2323
import static org.junit.Assert.assertNotNull;
2424
import static org.mockito.Matchers.any;
25+
import static org.mockito.Matchers.anyBoolean;
26+
import static org.mockito.Matchers.anyListOf;
27+
import static org.mockito.Matchers.anySetOf;
2528
import static org.mockito.Matchers.anyString;
2629
import static org.mockito.Matchers.eq;
2730
import static org.mockito.Mockito.doReturn;
2831
import static org.mockito.Mockito.mock;
2932
import static org.mockito.Mockito.spy;
33+
import static org.mockito.Mockito.times;
3034
import static org.mockito.Mockito.verify;
3135
import static org.mockito.Mockito.when;
3236

@@ -351,9 +355,6 @@ public void testCursorPosition() {
351355
}
352356
}
353357

354-
//(TODO zjffdu) temporary disable it.
355-
//https://github.com/apache/zeppelin/pull/3416
356-
@Ignore
357358
@Test
358359
public void credentialReplacement() throws Throwable {
359360
Note mockNote = mock(Note.class);
@@ -369,11 +370,16 @@ public void credentialReplacement() throws Throwable {
369370
spyParagraph.setInterpreter(mockInterpreter);
370371
doReturn(mockInterpreter).when(spyParagraph).getBindedInterpreter();
371372

373+
InterpreterSetting mockInterpreterSetting = mock(InterpreterSetting.class);
374+
when(mockInterpreterSetting.getStatus()).thenReturn(InterpreterSetting.Status.READY);
375+
when(mockInterpreterSetting.isUserAuthorized(anyListOf(String.class))).thenReturn(true);
376+
372377
ManagedInterpreterGroup mockInterpreterGroup = mock(ManagedInterpreterGroup.class);
373378
when(mockInterpreter.getInterpreterGroup()).thenReturn(mockInterpreterGroup);
374379
when(mockInterpreterGroup.getId()).thenReturn("mock_id_1");
375380
when(mockInterpreterGroup.getAngularObjectRegistry()).thenReturn(mock(AngularObjectRegistry.class));
376381
when(mockInterpreterGroup.getResourcePool()).thenReturn(mock(ResourcePool.class));
382+
when(mockInterpreterGroup.getInterpreterSetting()).thenReturn(mockInterpreterSetting);
377383
when(mockInterpreter.getFormType()).thenReturn(FormType.NONE);
378384

379385
ParagraphJobListener mockJobListener = mock(ParagraphJobListener.class);
@@ -386,23 +392,23 @@ public void credentialReplacement() throws Throwable {
386392
AuthenticationInfo user1 = new AuthenticationInfo("user1");
387393
spyParagraph.setAuthenticationInfo(user1);
388394

389-
spyParagraph.setText("val x = \"usr={user.ent}&pass={password.ent}\"");
395+
spyParagraph.setText("val x = \"usr={ent.user}&pass={ent.password}\"");
390396

391397
// Credentials should only be injected when it is enabled for an interpreter or when specified in a local property
392398
when(mockInterpreter.getProperty(Constants.INJECT_CREDENTIALS, "false")).thenReturn("false");
393399
spyParagraph.jobRun();
394-
verify(mockInterpreter).interpret(eq("val x = \"usr={user.ent}&pass={password.ent}\""), any(InterpreterContext.class));
400+
verify(mockInterpreter).interpret(eq("val x = \"usr={ent.user}&pass={ent.password}\""), any(InterpreterContext.class));
395401

396402
when(mockInterpreter.getProperty(Constants.INJECT_CREDENTIALS, "false")).thenReturn("true");
397-
mockInterpreter.setProperty(Constants.INJECT_CREDENTIALS, "true");
403+
mockInterpreter.setProperty(Constants.INJECT_CREDENTIALS, "false");
398404
spyParagraph.jobRun();
399405
verify(mockInterpreter).interpret(eq("val x = \"usr=user&pass=pwd\""), any(InterpreterContext.class));
400406

401407
// Check if local property override works
402-
when(mockInterpreter.getProperty(Constants.INJECT_CREDENTIALS, "false")).thenReturn("true");
408+
when(mockInterpreter.getProperty(Constants.INJECT_CREDENTIALS, "false")).thenReturn("false");
403409
spyParagraph.getLocalProperties().put(Constants.INJECT_CREDENTIALS, "true");
404410
spyParagraph.jobRun();
405-
verify(mockInterpreter).interpret(eq("val x = \"usr=user&pass=pwd\""), any(InterpreterContext.class));
411+
verify(mockInterpreter, times(2)).interpret(eq("val x = \"usr=user&pass=pwd\""), any(InterpreterContext.class));
406412

407413
}
408414
}

0 commit comments

Comments
 (0)