Skip to content

Commit 92b47e1

Browse files
committed
Exclude Spring password authority factor in tests
Refer to Spring documentation at: * https://docs.spring.io/spring-security/reference/api/java/org/springframework/security/core/authority/FactorGrantedAuthority.html * https://docs.spring.io/spring-security/reference/servlet/authentication/mfa.html#emfa * https://spring.io/blog/2025/10/21/multi-factor-authentication-in-spring-security-7#how-spring-security-models-mfa-through-progressive-authorization THis is a simple attempt to allow the creation of an incremental build that can be used for more testing with plugin BOM and the acceptance test harness.
1 parent 7221a98 commit 92b47e1

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

test/src/test/java/hudson/security/TokenBasedRememberMeServices2Test.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.springframework.security.core.Authentication;
3434
import org.springframework.security.core.AuthenticationException;
3535
import org.springframework.security.core.GrantedAuthority;
36+
import org.springframework.security.core.authority.FactorGrantedAuthority;
3637
import org.springframework.security.core.authority.SimpleGrantedAuthority;
3738
import org.springframework.security.core.userdetails.UserDetails;
3839
import org.springframework.security.core.userdetails.UsernameNotFoundException;
@@ -126,7 +127,8 @@ void basicFlow() throws Exception {
126127
wc.executeOnServer(() -> {
127128
Authentication a = Jenkins.getAuthentication2();
128129
assertEquals("bob", a.getName());
129-
assertEquals(Arrays.asList("authenticated", "myteam"), a.getAuthorities().stream().map(GrantedAuthority::getAuthority).collect(Collectors.toList()));
130+
assertEquals(Arrays.asList("authenticated", "myteam"),
131+
a.getAuthorities().stream().map(GrantedAuthority::getAuthority).filter(authority -> !authority.equals(FactorGrantedAuthority.PASSWORD_AUTHORITY)).collect(Collectors.toList()));
130132
return null;
131133
});
132134
}

test/src/test/java/jenkins/security/LastGrantedAuthoritiesPropertyTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.springframework.security.core.Authentication;
1919
import org.springframework.security.core.AuthenticationException;
2020
import org.springframework.security.core.GrantedAuthority;
21+
import org.springframework.security.core.authority.FactorGrantedAuthority;
2122
import org.springframework.security.core.authority.SimpleGrantedAuthority;
2223
import org.springframework.security.core.userdetails.User;
2324
import org.springframework.security.core.userdetails.UserDetails;
@@ -80,7 +81,7 @@ private void assertAuthorities(Authentication auth, String expected) {
8081
}
8182

8283
private void _assertAuthorities(Collection<? extends GrantedAuthority> grantedAuthorities, String expected) {
83-
List<String> authorities = grantedAuthorities.stream().map(GrantedAuthority::getAuthority).sorted().collect(Collectors.toList());
84+
List<String> authorities = grantedAuthorities.stream().map(GrantedAuthority::getAuthority).filter(authority -> !authority.equals(FactorGrantedAuthority.PASSWORD_AUTHORITY)).sorted().collect(Collectors.toList());
8485

8586
assertEquals(expected, String.join(":", authorities));
8687
}

0 commit comments

Comments
 (0)