mirror of
https://github.com/apache/zeppelin
synced 2026-05-24 09:38:26 +00:00
[ZEPPELIN-2880] - Fix username output when OIDC is enabled
This commit is contained in:
parent
72636897ca
commit
11d0729285
2 changed files with 55 additions and 2 deletions
|
|
@ -47,6 +47,7 @@
|
|||
<!--test library versions-->
|
||||
<selenium.java.version>2.48.2</selenium.java.version>
|
||||
<xml.apis.version>1.4.01</xml.apis.version>
|
||||
<powermock.version>1.6.6</powermock.version>
|
||||
|
||||
<!--plugin library versions-->
|
||||
<plugin.failsafe.version>2.16</plugin.failsafe.version>
|
||||
|
|
@ -374,8 +375,35 @@
|
|||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.powermock</groupId>
|
||||
<artifactId>powermock-module-junit4</artifactId>
|
||||
<version>${powermock.version}</version>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.javassist</groupId>
|
||||
<artifactId>javassist</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.powermock</groupId>
|
||||
<artifactId>powermock-api-mockito</artifactId>
|
||||
<version>${powermock.version}</version>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>hamcrest-core</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.objenesis</groupId>
|
||||
<artifactId>objenesis</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
|
|
|
|||
|
|
@ -17,18 +17,30 @@
|
|||
package org.apache.zeppelin.security;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import org.apache.commons.configuration.ConfigurationException;
|
||||
import org.apache.zeppelin.conf.ZeppelinConfiguration;
|
||||
import org.apache.zeppelin.utils.SecurityUtils;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.powermock.api.mockito.PowerMockito;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import sun.security.acl.PrincipalImpl;
|
||||
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.UnknownHostException;
|
||||
import java.net.InetAddress;
|
||||
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest(org.apache.shiro.SecurityUtils.class) // Static.class contains static methods
|
||||
public class SecurityUtilsTest {
|
||||
|
||||
@Mock
|
||||
org.apache.shiro.subject.Subject subject;
|
||||
|
||||
@Test
|
||||
public void isInvalid() throws URISyntaxException, UnknownHostException {
|
||||
assertFalse(SecurityUtils.isValidOrigin("http://127.0.1.1", ZeppelinConfiguration.create()));
|
||||
|
|
@ -87,4 +99,17 @@ public class SecurityUtilsTest {
|
|||
assertFalse(SecurityUtils.isValidOrigin("test123",
|
||||
new ZeppelinConfiguration(this.getClass().getResource("/zeppelin-site.xml"))));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void canGetPrincipalName() {
|
||||
String expectedName = "java.security.Principal.getName()";
|
||||
SecurityUtils.setIsEnabled(true);
|
||||
PowerMockito.mockStatic(org.apache.shiro.SecurityUtils.class);
|
||||
when(org.apache.shiro.SecurityUtils.getSubject()).thenReturn(subject);
|
||||
when(subject.isAuthenticated()).thenReturn(true);
|
||||
when(subject.getPrincipal()).thenReturn(new PrincipalImpl(expectedName));
|
||||
|
||||
assertEquals(expectedName, SecurityUtils.getPrincipal());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue