<commit_before>package org.osiam.security.helper

import org.springframework.security.oauth2.common.exceptions.InvalidClientException
import org.springframework.security.oauth2.common.exceptions.InvalidGrantException
import org.springframework.security.oauth2.common.exceptions.OAuth2Exception
import org.springframework.security.oauth2.common.exceptions.RedirectMismatchException
import org.springframework.security.oauth2.provider.AuthorizationRequest
import org.springframework.security.oauth2.provider.ClientDetailsService
import org.springframework.security.oauth2.provider.code.AuthorizationCodeServices
import org.springframework.security.oauth2.provider.code.AuthorizationRequestHolder
import org.springframework.security.oauth2.provider.token.AuthorizationServerTokenServices
import spock.lang.Specification

class LessStrictRedirectUriAuthorizationCodeTokenGranterTest extends Specification {
    def tokenService = Mock(AuthorizationServerTokenServices)
    def clientDetailsService = Mock(ClientDetailsService)
    def authzCodeServices = Mock(AuthorizationCodeServices)
    def underTest = new LessStrictRedirectUriAuthorizationCodeTokenGranter(tokenService, authzCodeServices, clientDetailsService)
    AuthorizationRequest authzRequest = Mock(AuthorizationRequest)
    AuthorizationRequestHolder storedAuth = Mock(AuthorizationRequestHolder)
    AuthorizationRequest authNRequest = Mock(AuthorizationRequest)
    def pendingRedirectUri = "localhost:unso"

    def setup(){

        authzCodeServices.consumeAuthorizationCode("12345") >> storedAuth
        storedAuth.getAuthenticationRequest() >> authNRequest
        authNRequest.getAuthorizationParameters() >> [redirect_uri: pendingRedirectUri]
        authNRequest.getRedirectUri() >> pendingRedirectUri

    }
    def set_redirect_uri(redirect_uri){
        authzRequest.getAuthorizationParameters() >> [code:"12345", redirect_uri: redirect_uri]
    }

    def "should continue if the pending redirect uri is equal to the send redirect uri"(){
        given:
          set_redirect_uri(pendingRedirectUri)

        when:
          def result = underTest.getOAuth2Authentication(authzRequest)
        then:
        result<commit_msg>forgot to fix unit test due to previous change<commit_after>package org.osiam.security.helper

import org.springframework.security.oauth2.common.exceptions.InvalidClientException
import org.springframework.security.oauth2.common.exceptions.InvalidGrantException
import org.springframework.security.oauth2.common.exceptions.OAuth2Exception
import org.springframework.security.oauth2.common.exceptions.RedirectMismatchException
import org.springframework.security.oauth2.provider.AuthorizationRequest
import org.springframework.security.oauth2.provider.ClientDetailsService
import org.springframework.security.oauth2.provider.code.AuthorizationCodeServices
import org.springframework.security.oauth2.provider.code.AuthorizationRequestHolder
import org.springframework.security.oauth2.provider.token.AuthorizationServerTokenServices
import spock.lang.Specification

class LessStrictRedirectUriAuthorizationCodeTokenGranterTest extends Specification {
    def tokenService = Mock(AuthorizationServerTokenServices)
    def clientDetailsService = Mock(ClientDetailsService)
    def authzCodeServices = Mock(AuthorizationCodeServices)
    def underTest = new LessStrictRedirectUriAuthorizationCodeTokenGranter(tokenService, clientDetailsService)
    AuthorizationRequest authzRequest = Mock(AuthorizationRequest)
    AuthorizationRequestHolder storedAuth = Mock(AuthorizationRequestHolder)
    AuthorizationRequest authNRequest = Mock(AuthorizationRequest)
    def pendingRedirectUri = "localhost:unso"

    def setup(){

        authzCodeServices.consumeAuthorizationCode("12345") >> storedAuth
        storedAuth.getAuthenticationRequest() >> authNRequest
        authNRequest.getAuthorizationParameters() >> [redirect_uri: pendingRedirectUri]
        underTest.authorizationCodeServices = authzCodeServices
        authNRequest.getRedirectUri() >> pendingRedirectUri

    }
    def set_redirect_uri(redirect_uri){
        authzRequest.getAuthorizationParameters() >> [code:"12345", redirect_uri: redirect_uri]
    }

    def "should continue if the pending redirect uri is equal to the send redirect uri"(){
        given:
          set_redirect_uri(pendingRedirectUri)

        when:
          def result = underTest.getOAuth2Authentication(authzRequest)
        then:
        result
{'fraction_non_alphanumeric': 0.06581883087907184, 'fraction_numerical': 0.009370816599732263, 'mean_word_length': 5.731231231231231, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5049386', 'n_tokens_mistral': 1091, 'n_tokens_neox': 1096, 'n_words': 194}