Skip to content

Commit

Permalink
SHIBUI-1774
Browse files Browse the repository at this point in the history
fixing tests
  • Loading branch information
chasegawa committed Jul 14, 2021
1 parent e7f10d1 commit 8896350
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package net.unicon.shibui.pac4j;

import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.data.domain.AuditorAware;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

import java.util.Optional;

@ConditionalOnProperty(name = "shibui.pac4j-enabled", havingValue = "true")
public class Pac4jAuditorAware implements AuditorAware<String> {

private static final String ANONYMOUS = "anonymousUser";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import edu.internet2.tier.shibboleth.admin.ui.security.model.User
import edu.internet2.tier.shibboleth.admin.ui.security.repository.RoleRepository
import edu.internet2.tier.shibboleth.admin.ui.security.repository.UserRepository
import edu.internet2.tier.shibboleth.admin.ui.service.EmailService

import org.pac4j.core.matching.matcher.PathMatcher
import org.pac4j.core.profile.CommonProfile
import org.pac4j.saml.profile.SAML2Profile
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.context.properties.EnableConfigurationProperties
Expand All @@ -17,6 +20,7 @@ import spock.lang.Subject

import javax.servlet.FilterChain
import javax.servlet.ServletRequest
import javax.servlet.http.HttpServletRequest
import javax.servlet.http.HttpServletResponse

/**
Expand All @@ -30,7 +34,7 @@ class AddNewUserFilterTests extends Specification {
RoleRepository roleRepository = Mock()
EmailService emailService = Mock()

ServletRequest request = Mock()
HttpServletRequest request = Mock()
HttpServletResponse response = Mock()
FilterChain chain = Mock()

Expand All @@ -51,7 +55,7 @@ class AddNewUserFilterTests extends Specification {
securityContext.getAuthentication() >> authentication
authentication.getPrincipal() >> saml2Profile

addNewUserFilter = new AddNewUserFilter(pac4jConfigurationProperties, userRepository, roleRepository, Optional.of(emailService))
addNewUserFilter = new AddNewUserFilter(pac4jConfigurationProperties, userRepository, roleRepository, new PathMatcher(), Optional.of(emailService))
saml2ProfileMapping = pac4jConfigurationProperties.saml2ProfileMapping
}

Expand All @@ -70,7 +74,7 @@ class AddNewUserFilterTests extends Specification {
addNewUserFilter.doFilter(request, response, chain)

then:
1 * roleRepository.save(_)
0 * roleRepository.save(_)
1 * userRepository.save(_ as User) >> { User user -> user }
1 * emailService.sendNewUserMail('newUser')
1 * response.sendRedirect("/unsecured/error.html")
Expand Down

0 comments on commit 8896350

Please sign in to comment.