Browse Source
RequestKey, JaasGrantedAuthority, and SwitchUserGrantedAuthority assume certain final members are non-null. Issue: gh-6892pull/6920/head
6 changed files with 123 additions and 4 deletions
@ -0,0 +1,50 @@
@@ -0,0 +1,50 @@
|
||||
/* |
||||
* Copyright 2002-2019 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.security.authentication.jaas; |
||||
|
||||
import org.junit.Test; |
||||
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy; |
||||
import org.springframework.security.authentication.jaas.JaasGrantedAuthority; |
||||
|
||||
/** |
||||
* |
||||
* @author Clement Ng |
||||
* |
||||
*/ |
||||
public class JaasGrantedAuthorityTests { |
||||
|
||||
/** |
||||
* @throws Exception |
||||
*/ |
||||
@Test |
||||
public void authorityWithNullRoleFailsAssertion() throws Exception { |
||||
assertThatThrownBy(() -> new JaasGrantedAuthority(null, null)) |
||||
.isInstanceOf(IllegalArgumentException.class) |
||||
.hasMessageContaining("role cannot be null"); |
||||
} |
||||
|
||||
/** |
||||
* @throws Exception |
||||
*/ |
||||
@Test |
||||
public void authorityWithNullPrincipleFailsAssertion() throws Exception { |
||||
assertThatThrownBy(() -> new JaasGrantedAuthority("role", null)) |
||||
.isInstanceOf(IllegalArgumentException.class) |
||||
.hasMessageContaining("principal cannot be null"); |
||||
} |
||||
} |
||||
@ -0,0 +1,49 @@
@@ -0,0 +1,49 @@
|
||||
/* |
||||
* Copyright 2002-2019 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
package org.springframework.security.web.authentication.switchuser; |
||||
|
||||
import org.junit.Test; |
||||
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy; |
||||
import org.springframework.security.web.authentication.switchuser.SwitchUserGrantedAuthority; |
||||
|
||||
/** |
||||
* |
||||
* @author Clement Ng |
||||
* |
||||
*/ |
||||
public class SwitchUserGrantedAuthorityTests { |
||||
|
||||
/** |
||||
* @throws Exception |
||||
*/ |
||||
@Test |
||||
public void authorityWithNullRoleFailsAssertion() throws Exception { |
||||
assertThatThrownBy(() -> new SwitchUserGrantedAuthority(null, null)) |
||||
.isInstanceOf(IllegalArgumentException.class) |
||||
.hasMessage("role cannot be null"); |
||||
} |
||||
|
||||
/** |
||||
* @throws Exception |
||||
*/ |
||||
@Test |
||||
public void authorityWithNullSourceFailsAssertion() throws Exception { |
||||
assertThatThrownBy(() -> new SwitchUserGrantedAuthority("role", null)) |
||||
.isInstanceOf(IllegalArgumentException.class) |
||||
.hasMessage("source cannot be null"); |
||||
} |
||||
} |
||||
Loading…
Reference in new issue