/*
 *     Copyright (C) 2015 ASIP Santé
 */
package fr.asipsante.mss.connectkit.auth;

import fr.asipsante.mss.connectkit.paos.Saml2ProtocolException;
import fr.asipsante.mss.connectkit.paos.OTPAuthSaml2Driver;
import static org.junit.Assert.*;

import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

import fr.asipsante.mss.connectkit.connection.HttpsConnectionFactory;

public class OTPAuthSaml2DriverUnitTest {
    private class OTPAuthSaml2DriverTest extends OTPAuthSaml2Driver {

        public OTPAuthSaml2DriverTest(String defaultEncoding,
                HttpsConnectionFactory connectionFactory, String authHostname,
                int authPort, String authPath, String idOTPCanal,
                String OTPCanalPassword, String idNatPs) {
            super(defaultEncoding, connectionFactory, authHostname, authPort,
                    authPath, idOTPCanal, OTPCanalPassword, idNatPs);
        }

        public String getNextURL(String authorizationHeader)
                throws Saml2ProtocolException {
            return super.getNextURL(authorizationHeader);
        }

    }

    @Mock
    private HttpsConnectionFactory connectionFactory;

    @Before
    public void initMock() {
        MockitoAnnotations.initMocks(this);
    }

    @Test
    public void nextURLFormeInitiale() throws Saml2ProtocolException {
        OTPAuthSaml2DriverTest tester = new OTPAuthSaml2DriverTest("",
                connectionFactory, "", -1, "", "", "", "");
        String actual = tester
                .getNextURL(" OTP nextUrl=/openam/UI/Login?forward=true&realm=%2Fasip&goto=%2FSSOSoap%2FmetaAlias%2Fasip%2Fidp%3FReqID%3Da2jj2dg5h0hbff5j493aiehfg23557g&spEntityID=mss-msg-services");
        String expected = "/openam/UI/Login?forward=true&realm=%2Fasip&goto=%2FSSOSoap%2FmetaAlias%2Fasip%2Fidp%3FReqID%3Da2jj2dg5h0hbff5j493aiehfg23557g&spEntityID=mss-msg-services";
        assertEquals(expected, actual);
    }

    @Test
    public void nextURLNoinitialHeaderWhitespace()
            throws Saml2ProtocolException {
        OTPAuthSaml2DriverTest tester = new OTPAuthSaml2DriverTest("",
                connectionFactory, "", -1, "", "", "", "");
        String actual = tester
                .getNextURL("OTP nextUrl=/openam/UI/Login?forward=true&realm=%2Fasip&goto=%2FSSOSoap%2FmetaAlias%2Fasip%2Fidp%3FReqID%3Da2jj2dg5h0hbff5j493aiehfg23557g&spEntityID=mss-msg-services");
        String expected = "/openam/UI/Login?forward=true&realm=%2Fasip&goto=%2FSSOSoap%2FmetaAlias%2Fasip%2Fidp%3FReqID%3Da2jj2dg5h0hbff5j493aiehfg23557g&spEntityID=mss-msg-services";
        assertEquals(expected, actual);
    }
}
