<?php

namespace AuthStack\SAMLServiceProvider\tests\units\Model;

use LightSaml\Model\XmlDSig\SignatureWriter;
use mageekguy\atoum;
use AuthStack\SAMLServiceProvider\Model\ServiceProvider as SP;
use RobRichards\XMLSecLibs\XMLSecurityKey;

class ServiceProvider extends atoum
{
    public function testSP()
    {
        $this->given($sp = new SP())
            ->then
            ->string($sp->getEntityId())->isEqualTo('https://sp.tld/saml/entity.xml')
            ->string($sp->getIdPEntityId())->isEqualTo('https://authstack')
            ->string($sp->getBaseUrl())->isEqualTo('https://sp.tld')
            ->string($sp->getNameIdFormat())->isEqualTo('urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress')
            ->boolean($sp->wantsSignedMessages())->isTrue()
            ->boolean($sp->wantsSignedAssertions())->isFalse()
            ->boolean($sp->wantsEncryptedAssertions())->isFalse()
            ->string($sp->getACSPath())->isEqualTo('/saml/acs')
            ->string($sp->getACSBinding())->isEqualTo('urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST')
            ->string($sp->getACSUrl())->isEqualTo('https://sp.tld/saml/acs')
            ->string($sp->getLogoutServicePath())->isEqualTo('/saml/slo')
            ->string($sp->getLogoutServiceBinding())->isEqualTo('urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST')
            ->string($sp->getLogoutServiceUrl())->isEqualTo('https://sp.tld/saml/slo')
            ->boolean($sp->validateSignature())->isTrue()
            ->boolean($sp->validateDestination())->isTrue()
            ->boolean($sp->validateIssuer())->isTrue()
            ->boolean($sp->validateDestination())->isTrue()
            ->boolean($sp->validateLifetime())->isTrue()
            ->object($sp->getUpperDT())->isInstanceOf(\DateTime::class)
            ->object($sp->getLowerDT())->isInstanceOf(\DateTime::class)
            ->string($sp->getValidationUpperTimeBoundary())->isEqualTo('+1 minute')
            ->string($sp->getValidationLowerTimeBoundary())->isEqualTo('-1 minute')
            ->array($sp->getSigningKey())->hasKeys(['x509', 'private', 'passphrase', 'algorithm'])
            ->array($sp->getDecryptionKey())->hasKeys(['x509', 'private', 'passphrase', 'algorithm'])
            ->object($sp->getSignatureWriter())->isInstanceOf(SignatureWriter::class)
            ->object($sp->getDecrypter())->isInstanceOf(XMLSecurityKey::class)
            ;
    }
}