From 2b099343631e122b89d3c5bdecadd5c9d00bf9bc Mon Sep 17 00:00:00 2001 From: Andrew Hoffmann <andrew.hoffmann@wisc.edu> Date: Tue, 28 Apr 2015 10:40:33 -0500 Subject: [PATCH] Added the checkLOA method to the RpcNetidClient interface. Created a skeleton implementation in RpcNetidClientSoap. Created the unit tests for the new method, which are all failing at this point. --- src/main/edu/wisc/doit/RpcNetidClient.php | 20 +++ src/main/edu/wisc/doit/RpcNetidClientSoap.php | 14 +- src/test/RpcNetidClientSoapTest.php | 147 ++++++++++++++++++ 3 files changed, 179 insertions(+), 2 deletions(-) diff --git a/src/main/edu/wisc/doit/RpcNetidClient.php b/src/main/edu/wisc/doit/RpcNetidClient.php index 9f626a5..154609d 100644 --- a/src/main/edu/wisc/doit/RpcNetidClient.php +++ b/src/main/edu/wisc/doit/RpcNetidClient.php @@ -90,6 +90,26 @@ interface RpcNetidClient { * @return RpcNetidStructValidationResponse indicates if valid and the reason for invalid */ function passwordChoicePolicyCheck( $password ); + + /** + * Verifies the identity of a UW-Madison user using his or her NetID, date of birth, + * and optional Wiscard number. + * + * <p>This method will take into account the user's LOA (level of assurance). If the user + * is LOA2 or higher, the WisCard number is required. Otherwise, it is ignored.</p> + * + * <p>The method returns a {@link RpcNetidStructValidationResponse} object. If + * {@link RpcNetidStructValidationResponse::getIsValid} returns true, the identity is verified. + * Otherwise, it will return false with zero or more reasons returned by + * {@link RpcNetidStructValidationResponse::getReasons} + * + * @param string $uid user's NetID + * @param \DateTime $birthdate user's date of birth + * @param int $wiscard user's 11-digit Wiscard number + * @return RpcNetidStructValidationResponse validation response including reasons for failure. + */ + function checkLOA( $uid, \DateTime $birthdate, $wiscard = null ); + } /** diff --git a/src/main/edu/wisc/doit/RpcNetidClientSoap.php b/src/main/edu/wisc/doit/RpcNetidClientSoap.php index 0433fb0..1c9783c 100644 --- a/src/main/edu/wisc/doit/RpcNetidClientSoap.php +++ b/src/main/edu/wisc/doit/RpcNetidClientSoap.php @@ -123,6 +123,16 @@ class RpcNetidClientSoap implements RpcNetidClient { throw new RpcNetidClientSoapException("Unexpected status code: {$result->result}", RpcNetidClientSoapException::UNEXPECTED_STATUS_CODE ); + } + + /** + * (non-PHPdoc) + * @see \edu\wisc\doit\RpcNetidClient::checkLOA() + */ + public function checkLOA( $uid, \DateTime $birthdate, $wiscard = null ) { + + + } /** @@ -360,7 +370,7 @@ class RpcNetidClientSoap implements RpcNetidClient { * Exception class for {@link RpcNetidClientSoap} */ class RpcNetidClientSoapException extends RpcNetidClientException { - const UNEXPECTED_STATUS_CODE = 100; - const UNEXPECTED_RESPONSE = 101; + const UNEXPECTED_STATUS_CODE = 100; // web service returns status code that cannot be handled (runtime exception) + const UNEXPECTED_RESPONSE = 101; // web service returns content that is not expected const INVALID_EMAIL = 102; } \ No newline at end of file diff --git a/src/test/RpcNetidClientSoapTest.php b/src/test/RpcNetidClientSoapTest.php index a19db3b..56ec113 100644 --- a/src/test/RpcNetidClientSoapTest.php +++ b/src/test/RpcNetidClientSoapTest.php @@ -602,5 +602,152 @@ class RpcNetidClientSoapTest extends PHPUnit_Framework_TestCase { $this->assertTrue($returnValue->getIsValid()); } + + /* checkLOA tests ------------------------------- */ + + /** + * @test Wiscard is not 11 digits throws exception + * @expectedException DomainException + */ + function checkLOA_wiscard_not_11_digits_throws() { + + $result = new stdClass(); + $result->result = 200; + + $this->mockSoapClient->expects($this->any())->method('passwordChoicePolicyCheck')->will($this->returnValue($result)); + $client = new RpcNetidClientSoap($this->mockSoapClient); + $client->checkLOA( "jsmith", new \DateTime(), 12345 ); + + } + + /** + * @test returns false if 400 is returned by web service + */ + function checkLOA_400_returns_false() { + + $result = new stdClass(); + $result->result = 400; + + $this->mockSoapClient->expects($this->any())->method('passwordChoicePolicyCheck')->will($this->returnValue($result)); + $client = new RpcNetidClientSoap($this->mockSoapClient); + $returned = $client->checkLOA( "jsmith", new \DateTime(), 12345678901 ); + $this->assertInstanceOf('edu\wisc\doit\RpcNetidStructValidationResponse', $returned ); + $this->assertFalse( $returned->getIsValid() ); + + } + + /** + * @test throws exception if web service returns 401 (invalid parameters) + * @expectedException RpcNetidClientSoapException + * @expectedExceptionCode 100 + */ + function checkLOA_401_throws() { + + $result = new stdClass(); + $result->result = 401; + + $this->mockSoapClient->expects($this->any())->method('passwordChoicePolicyCheck')->will($this->returnValue($result)); + $client = new RpcNetidClientSoap($this->mockSoapClient); + $client->checkLOA( "jsmith", new \DateTime(), 12345678901 ); + + } + + /** + * @test throws exception if web service returns 402 (No PVI found for UID) + * @expectedException RpcNetidClientSoapException + * @expectedExceptionCode 100 + */ + function checkLOA_402_throws() { + + $result = new stdClass(); + $result->result = 402; + + $this->mockSoapClient->expects($this->any())->method('passwordChoicePolicyCheck')->will($this->returnValue($result)); + $client = new RpcNetidClientSoap($this->mockSoapClient); + $client->checkLOA( "jsmith", new \DateTime(), 12345678901 ); + + } + + /** + * @test throws exception if web service returns 403 (No LOA found for UID) + * @expectedException RpcNetidClientSoapException + * @expectedExceptionCode 100 + */ + function checkLOA_403_throws() { + + $result = new stdClass(); + $result->result = 403; + + $this->mockSoapClient->expects($this->any())->method('passwordChoicePolicyCheck')->will($this->returnValue($result)); + $client = new RpcNetidClientSoap($this->mockSoapClient); + $client->checkLOA( "jsmith", new \DateTime(), 12345678901 ); + + } + + /** + * @test throws exception if web service returns 404 (No Wiscard eligibility found for user) + * @expectedException RpcNetidClientSoapException + * @expectedExceptionCode 100 + */ + function checkLOA_404_throws() { + + $result = new stdClass(); + $result->result = 404; + + $this->mockSoapClient->expects($this->any())->method('passwordChoicePolicyCheck')->will($this->returnValue($result)); + $client = new RpcNetidClientSoap($this->mockSoapClient); + $client->checkLOA( "jsmith", new \DateTime(), 12345678901 ); + + } + + /** + * @test returns false validation object with reason if web service returns 405 (Person is LOA2, but the Wiscard was missing) + */ + function checkLOA_405_returns_false_with_reason() { + + $result = new stdClass(); + $result->result = 405; + + $this->mockSoapClient->expects($this->any())->method('passwordChoicePolicyCheck')->will($this->returnValue($result)); + $client = new RpcNetidClientSoap($this->mockSoapClient); + $returned = $client->checkLOA( "jsmith", new \DateTime() ); + + $this->assertInstanceOf('edu\wisc\doit\RpcNetidStructValidationResponse', $returned ); + $this->assertFalse( $returned->getIsValid() ); + $this->assertNotEmpty( $returned->getReasons() ); + + } + + /** + * @test returns true validation object when web service returns 200 + */ + function checkLOA_200_returns_true() { + + $result = new stdClass(); + $result->result = 200; + + $this->mockSoapClient->expects($this->any())->method('passwordChoicePolicyCheck')->will($this->returnValue($result)); + $client = new RpcNetidClientSoap($this->mockSoapClient); + $returned = $client->checkLOA( "jsmith", new \DateTime(), 12345678901 ); + + $this->assertInstanceOf('edu\wisc\doit\RpcNetidStructValidationResponse', $returned ); + $this->assertTrue( $returned->getIsValid() ); + + } + + /** + * @test throws exception if an unexpected response code was received by web service + * @expectedException RpcNetidClientSoapException + * @expectedExceptionCode 100 + */ + function checkLOA_500_throws_exception() { + $result = new stdClass(); + $result->result = 500; + + $this->mockSoapClient->expects($this->any())->method('passwordChoicePolicyCheck')->will($this->returnValue($result)); + $client = new RpcNetidClientSoap($this->mockSoapClient); + $client->checkLOA( "jsmith", new \DateTime(), 12345678901 ); + + } } -- GitLab