<commit_before>package ee.tuleva.onboarding.auth

import com.codeborne.security.mobileid.MobileIDSession
import ee.tuleva.onboarding.BaseControllerSpec
import ee.tuleva.onboarding.auth.command.AuthenticationType
import ee.tuleva.onboarding.auth.idcard.IdCardAuthService
import ee.tuleva.onboarding.auth.mobileid.MobileIdAuthService
import ee.tuleva.onboarding.auth.mobileid.MobileIdFixture
import ee.tuleva.onboarding.auth.session.GenericSessionStore
import ee.tuleva.onboarding.auth.smartid.SmartIdAuthService
import ee.tuleva.onboarding.auth.smartid.SmartIdFixture
import ee.tuleva.onboarding.auth.smartid.SmartIdSession
import org.springframework.http.HttpStatus
import org.springframework.http.MediaType
import org.springframework.mock.web.MockHttpServletResponse
import org.springframework.test.web.servlet.MockMvc

import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post

class AuthControllerSpec extends BaseControllerSpec {

    MobileIdAuthService mobileIdAuthService = Mock(MobileIdAuthService)
    SmartIdAuthService smartIdAuthService = Mock(SmartIdAuthService)
    GenericSessionStore sessionStore = Mock(GenericSessionStore)
    IdCardAuthService idCardAuthService = Mock(IdCardAuthService)
    AuthController controller = new AuthController(mobileIdAuthService, smartIdAuthService, sessionStore, idCardAuthService)
    private MockMvc mockMvc

    def setup() {
        mockMvc = mockMvc(controller)
        controller.idCardSecretToken = "Bearer secretz"
    }

    def "Authenticate: Initiate mobile id authentication (deprecated)"() {
        given:
        1 * mobileIdAuthService.startLogin(MobileIdFixture.samplePhoneNumber) >> MobileIdFixture.sampleMobileIdSession
        1 * sessionStore.save(_ as MobileIDSession)
        when:
        MockHttpServletResponse response = mockMvc
                .perform(post("/authenticate")
                .contentType(MediaType.APPLICATION_JSON)
                .content(mapper.writeValueAsString(sampleDeprecatedAuthenticateCommand()))).andReturn().response
        then:
        response.status == HttpStatus.OK.value()
    }

    def "Authenticate: Initiate mobile id authentication"() {
        given:
        1 * mobileIdAuthService.startLogin(MobileIdFixture.samplePhoneNumber) >> MobileIdFixture.sampleMobileIdSession
        1 * sessionStore.save(_ as MobileIDSession)<commit_msg>Remove property<commit_after>package ee.tuleva.onboarding.auth

import com.codeborne.security.mobileid.MobileIDSession
import ee.tuleva.onboarding.BaseControllerSpec
import ee.tuleva.onboarding.auth.command.AuthenticationType
import ee.tuleva.onboarding.auth.idcard.IdCardAuthService
import ee.tuleva.onboarding.auth.mobileid.MobileIdAuthService
import ee.tuleva.onboarding.auth.mobileid.MobileIdFixture
import ee.tuleva.onboarding.auth.session.GenericSessionStore
import ee.tuleva.onboarding.auth.smartid.SmartIdAuthService
import ee.tuleva.onboarding.auth.smartid.SmartIdFixture
import ee.tuleva.onboarding.auth.smartid.SmartIdSession
import org.springframework.http.HttpStatus
import org.springframework.http.MediaType
import org.springframework.mock.web.MockHttpServletResponse
import org.springframework.test.web.servlet.MockMvc

import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post

class AuthControllerSpec extends BaseControllerSpec {

    MobileIdAuthService mobileIdAuthService = Mock(MobileIdAuthService)
    SmartIdAuthService smartIdAuthService = Mock(SmartIdAuthService)
    GenericSessionStore sessionStore = Mock(GenericSessionStore)
    IdCardAuthService idCardAuthService = Mock(IdCardAuthService)
    AuthController controller = new AuthController(mobileIdAuthService, smartIdAuthService, sessionStore, idCardAuthService)
    private MockMvc mockMvc

    def setup() {
        mockMvc = mockMvc(controller)
    }

    def "Authenticate: Initiate mobile id authentication (deprecated)"() {
        given:
        1 * mobileIdAuthService.startLogin(MobileIdFixture.samplePhoneNumber) >> MobileIdFixture.sampleMobileIdSession
        1 * sessionStore.save(_ as MobileIDSession)
        when:
        MockHttpServletResponse response = mockMvc
                .perform(post("/authenticate")
                .contentType(MediaType.APPLICATION_JSON)
                .content(mapper.writeValueAsString(sampleDeprecatedAuthenticateCommand()))).andReturn().response
        then:
        response.status == HttpStatus.OK.value()
    }

    def "Authenticate: Initiate mobile id authentication"() {
        given:
        1 * mobileIdAuthService.startLogin(MobileIdFixture.samplePhoneNumber) >> MobileIdFixture.sampleMobileIdSession
        1 * sessionStore.save(_ as MobileIDSession)
{'fraction_non_alphanumeric': 0.07581967213114754, 'fraction_numerical': 0.001639344262295082, 'mean_word_length': 4.859543817527011, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '6816781', 'n_tokens_mistral': 1370, 'n_tokens_neox': 1341, 'n_words': 213}