From b752316d4d51005249836b11af151cf0a00f065f Mon Sep 17 00:00:00 2001 From: Andrew Hoffmann <andrew.hoffmann@wisc.edu> Date: Tue, 28 Apr 2015 11:19:39 -0500 Subject: [PATCH] Implemented RpcNetidClientSoap::checkLOA. All unit tests pass. Added a constant to the RpcNetidStructValidationResponse class to strictly represent the reason that a user needs to enter in a Wiscard. Updated the WSDL in the test resources to reflect the new checkLOA method. --- src/main/edu/wisc/doit/RpcNetidClientSoap.php | 53 +++++ .../doit/RpcNetidStructValidationResponse.php | 10 +- src/test/RpcNetidClientSoapTest.php | 35 +-- src/test/resources/rpctest-netid.wsdl | 205 ++++++++++++------ 4 files changed, 220 insertions(+), 83 deletions(-) diff --git a/src/main/edu/wisc/doit/RpcNetidClientSoap.php b/src/main/edu/wisc/doit/RpcNetidClientSoap.php index 1c9783c..2bce093 100644 --- a/src/main/edu/wisc/doit/RpcNetidClientSoap.php +++ b/src/main/edu/wisc/doit/RpcNetidClientSoap.php @@ -131,7 +131,60 @@ class RpcNetidClientSoap implements RpcNetidClient { */ public function checkLOA( $uid, \DateTime $birthdate, $wiscard = null ) { + if ( is_string( $uid ) !== true or empty( $uid ) === true ) { + throw new \InvalidArgumentException( "uid must be a nonempty string" ); + } + + if ( is_null( $wiscard ) === false ) { + if ( is_int( $wiscard ) !== true ) { + throw new \InvalidArgumentException( "wiscard must be at least a 10-digit integer"); + } + if ( strlen(strval($wiscard)) < 10 ) { + throw new \DomainException( "wiscard must be at least a 10-digit integer"); + } + } + + $parameters = array(); + $parameters['uid'] = strval( $uid ); + $parameters['birthdate'] = $birthdate->format("m-d-Y"); + if ( is_null( $wiscard ) === false ) { $parameters['cardid'] = strval( $wiscard ); } + + $result = $this->getSoapClient()->checkLOA( $parameters ); + + if ( isset( $result->result ) !== true ) { + throw new RpcNetidClientSoapException( "Web service did not return a result code", RpcNetidClientSoapException::UNEXPECTED_RESPONSE ); + } + + switch( $result->result ) { + case 200: + return new RpcNetidStructValidationResponse(true, array()); + break; + case 400: + return new RpcNetidStructValidationResponse(false, array()); + break; + case 401: + throw new RpcNetidClientSoapException("Web service returned 401: invalid input parameters", + RpcNetidClientSoapException::UNEXPECTED_STATUS_CODE ); + break; + case 402: + throw new RpcNetidClientSoapException("Web service returned 402: no PVI found for uid", + RpcNetidClientSoapException::UNEXPECTED_STATUS_CODE ); + break; + case 403: + throw new RpcNetidClientSoapException("Web service returned 403: no LOA found for uid", + RpcNetidClientSoapException::UNEXPECTED_STATUS_CODE ); + break; + case 404: + throw new RpcNetidClientSoapException("no Wiscard eligibility data found for uid", + RpcNetidClientSoapException::UNEXPECTED_STATUS_CODE ); + break; + case 405: + return new RpcNetidStructValidationResponse(false, array(RpcNetidStructValidationResponse::REASON_NEEDS_WISCARD ) ); + break; + } + throw new RpcNetidClientSoapException("Unexpected status code: {$result->result}", + RpcNetidClientSoapException::UNEXPECTED_STATUS_CODE ); } diff --git a/src/main/edu/wisc/doit/RpcNetidStructValidationResponse.php b/src/main/edu/wisc/doit/RpcNetidStructValidationResponse.php index 9c7e2c1..729d61c 100644 --- a/src/main/edu/wisc/doit/RpcNetidStructValidationResponse.php +++ b/src/main/edu/wisc/doit/RpcNetidStructValidationResponse.php @@ -3,7 +3,8 @@ namespace edu\wisc\doit; /** - * Represents a validation response for a NetID password + * Represents a validation response. This can be used when information about why something + * is invalid needs to be communicated. */ class RpcNetidStructValidationResponse { @@ -11,9 +12,14 @@ class RpcNetidStructValidationResponse { /** @var bool true if valid, false if invalid */ private $isValid; - /** @var string[] the reasons for a password being invalid */ + /** @var mixed[] the reasons for being invalid */ private $reasons; + /** + * @var int encoded reason for when a user needs a Wiscard number + */ + const REASON_NEEDS_WISCARD = 100; + /** * @param bool $isValid * @param string $reason diff --git a/src/test/RpcNetidClientSoapTest.php b/src/test/RpcNetidClientSoapTest.php index 56ec113..46fb41a 100644 --- a/src/test/RpcNetidClientSoapTest.php +++ b/src/test/RpcNetidClientSoapTest.php @@ -5,6 +5,7 @@ use edu\wisc\doit\RpcNetidClientSoapConfig; use edu\wisc\doit\RpcNetidStructGetQuestionsRequest; use edu\wisc\doit\RpcNetidStructQuestion; use edu\wisc\doit\RpcNetidStructNetidResponse; +use edu\wisc\doit\RpcNetidStructValidationResponse; /** * Unit tests for the {@link edu\wisc\doit\RpcNetidClientSoap} class. @@ -606,15 +607,15 @@ class RpcNetidClientSoapTest extends PHPUnit_Framework_TestCase { /* checkLOA tests ------------------------------- */ /** - * @test Wiscard is not 11 digits throws exception + * @test Wiscard is less than 10 digits throws exception * @expectedException DomainException */ - function checkLOA_wiscard_not_11_digits_throws() { + function checkLOA_wiscard_less_than_10_digits_throws() { $result = new stdClass(); $result->result = 200; - $this->mockSoapClient->expects($this->any())->method('passwordChoicePolicyCheck')->will($this->returnValue($result)); + $this->mockSoapClient->expects($this->any())->method('checkLOA')->will($this->returnValue($result)); $client = new RpcNetidClientSoap($this->mockSoapClient); $client->checkLOA( "jsmith", new \DateTime(), 12345 ); @@ -628,7 +629,7 @@ class RpcNetidClientSoapTest extends PHPUnit_Framework_TestCase { $result = new stdClass(); $result->result = 400; - $this->mockSoapClient->expects($this->any())->method('passwordChoicePolicyCheck')->will($this->returnValue($result)); + $this->mockSoapClient->expects($this->any())->method('checkLOA')->will($this->returnValue($result)); $client = new RpcNetidClientSoap($this->mockSoapClient); $returned = $client->checkLOA( "jsmith", new \DateTime(), 12345678901 ); $this->assertInstanceOf('edu\wisc\doit\RpcNetidStructValidationResponse', $returned ); @@ -638,7 +639,7 @@ class RpcNetidClientSoapTest extends PHPUnit_Framework_TestCase { /** * @test throws exception if web service returns 401 (invalid parameters) - * @expectedException RpcNetidClientSoapException + * @expectedException edu\wisc\doit\RpcNetidClientSoapException * @expectedExceptionCode 100 */ function checkLOA_401_throws() { @@ -646,7 +647,7 @@ class RpcNetidClientSoapTest extends PHPUnit_Framework_TestCase { $result = new stdClass(); $result->result = 401; - $this->mockSoapClient->expects($this->any())->method('passwordChoicePolicyCheck')->will($this->returnValue($result)); + $this->mockSoapClient->expects($this->any())->method('checkLOA')->will($this->returnValue($result)); $client = new RpcNetidClientSoap($this->mockSoapClient); $client->checkLOA( "jsmith", new \DateTime(), 12345678901 ); @@ -654,7 +655,7 @@ class RpcNetidClientSoapTest extends PHPUnit_Framework_TestCase { /** * @test throws exception if web service returns 402 (No PVI found for UID) - * @expectedException RpcNetidClientSoapException + * @expectedException edu\wisc\doit\RpcNetidClientSoapException * @expectedExceptionCode 100 */ function checkLOA_402_throws() { @@ -662,7 +663,7 @@ class RpcNetidClientSoapTest extends PHPUnit_Framework_TestCase { $result = new stdClass(); $result->result = 402; - $this->mockSoapClient->expects($this->any())->method('passwordChoicePolicyCheck')->will($this->returnValue($result)); + $this->mockSoapClient->expects($this->any())->method('checkLOA')->will($this->returnValue($result)); $client = new RpcNetidClientSoap($this->mockSoapClient); $client->checkLOA( "jsmith", new \DateTime(), 12345678901 ); @@ -670,7 +671,7 @@ class RpcNetidClientSoapTest extends PHPUnit_Framework_TestCase { /** * @test throws exception if web service returns 403 (No LOA found for UID) - * @expectedException RpcNetidClientSoapException + * @expectedException edu\wisc\doit\RpcNetidClientSoapException * @expectedExceptionCode 100 */ function checkLOA_403_throws() { @@ -678,7 +679,7 @@ class RpcNetidClientSoapTest extends PHPUnit_Framework_TestCase { $result = new stdClass(); $result->result = 403; - $this->mockSoapClient->expects($this->any())->method('passwordChoicePolicyCheck')->will($this->returnValue($result)); + $this->mockSoapClient->expects($this->any())->method('checkLOA')->will($this->returnValue($result)); $client = new RpcNetidClientSoap($this->mockSoapClient); $client->checkLOA( "jsmith", new \DateTime(), 12345678901 ); @@ -686,7 +687,7 @@ class RpcNetidClientSoapTest extends PHPUnit_Framework_TestCase { /** * @test throws exception if web service returns 404 (No Wiscard eligibility found for user) - * @expectedException RpcNetidClientSoapException + * @expectedException edu\wisc\doit\RpcNetidClientSoapException * @expectedExceptionCode 100 */ function checkLOA_404_throws() { @@ -694,7 +695,7 @@ class RpcNetidClientSoapTest extends PHPUnit_Framework_TestCase { $result = new stdClass(); $result->result = 404; - $this->mockSoapClient->expects($this->any())->method('passwordChoicePolicyCheck')->will($this->returnValue($result)); + $this->mockSoapClient->expects($this->any())->method('checkLOA')->will($this->returnValue($result)); $client = new RpcNetidClientSoap($this->mockSoapClient); $client->checkLOA( "jsmith", new \DateTime(), 12345678901 ); @@ -708,13 +709,13 @@ class RpcNetidClientSoapTest extends PHPUnit_Framework_TestCase { $result = new stdClass(); $result->result = 405; - $this->mockSoapClient->expects($this->any())->method('passwordChoicePolicyCheck')->will($this->returnValue($result)); + $this->mockSoapClient->expects($this->any())->method('checkLOA')->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() ); + $this->assertContains( RpcNetidStructValidationResponse::REASON_NEEDS_WISCARD, $returned->getReasons() ); } @@ -726,7 +727,7 @@ class RpcNetidClientSoapTest extends PHPUnit_Framework_TestCase { $result = new stdClass(); $result->result = 200; - $this->mockSoapClient->expects($this->any())->method('passwordChoicePolicyCheck')->will($this->returnValue($result)); + $this->mockSoapClient->expects($this->any())->method('checkLOA')->will($this->returnValue($result)); $client = new RpcNetidClientSoap($this->mockSoapClient); $returned = $client->checkLOA( "jsmith", new \DateTime(), 12345678901 ); @@ -737,14 +738,14 @@ class RpcNetidClientSoapTest extends PHPUnit_Framework_TestCase { /** * @test throws exception if an unexpected response code was received by web service - * @expectedException RpcNetidClientSoapException + * @expectedException edu\wisc\doit\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)); + $this->mockSoapClient->expects($this->any())->method('checkLOA')->will($this->returnValue($result)); $client = new RpcNetidClientSoap($this->mockSoapClient); $client->checkLOA( "jsmith", new \DateTime(), 12345678901 ); diff --git a/src/test/resources/rpctest-netid.wsdl b/src/test/resources/rpctest-netid.wsdl index 8209b52..f8987db 100644 --- a/src/test/resources/rpctest-netid.wsdl +++ b/src/test/resources/rpctest-netid.wsdl @@ -33,6 +33,29 @@ targetNamespace="http://rpc.services.wisc.edu/UWDS/WebService/NetID"> <xsd:complexType name="FaultType"><xsd:sequence> <xsd:element name="faultcode" type="xsd:QName"/><xsd:element name="faultstring" type="xsd:string"/><xsd:element name="faultactor" type="xsd:anyURI" minOccurs="0"/> </xsd:sequence></xsd:complexType> +<xsd:element name="checkLOA"> + <xsd:complexType> + <xsd:sequence> + <xsd:element minOccurs="1" maxOccurs="1" name="uid" type="xsd:string"/> + <xsd:element minOccurs="0" maxOccurs="1" name="cardid" type="xsd:string"/> + <xsd:element minOccurs="1" maxOccurs="1" name="birthdate" type="xsd:string"/> + </xsd:sequence> + </xsd:complexType> + + +</xsd:element> +<xsd:element name="checkLOAResponse"> + + <xsd:complexType> + <xsd:sequence> + <xsd:element minOccurs="1" maxOccurs="1" name="result" type="xsd:integer"/> + </xsd:sequence> + </xsd:complexType> + +</xsd:element> +<xsd:element name="checkLOAFault"> +<xsd:complexType><xsd:sequence><xsd:element name="Fault" type="tns:FaultType"/></xsd:sequence></xsd:complexType> +</xsd:element> <xsd:element name="Authenticate"> <xsd:complexType> <xsd:sequence> @@ -85,7 +108,7 @@ targetNamespace="http://rpc.services.wisc.edu/UWDS/WebService/NetID"> <xsd:element minOccurs="0" maxOccurs="1" name="system" type="xsd:string"/> <xsd:element minOccurs="0" maxOccurs="1" name="domain" type="xsd:string"/> <xsd:element minOccurs="1" maxOccurs="1" name="uid" type="xsd:string"/> - <xsd:element minOccurs="1" maxOccurs="1" name="cardid" type="xsd:string"/> + <xsd:element minOccurs="0" maxOccurs="1" name="cardid" type="xsd:string"/> <xsd:element minOccurs="1" maxOccurs="1" name="birthdate" type="xsd:string"/> </xsd:sequence> </xsd:complexType> @@ -625,6 +648,28 @@ targetNamespace="http://rpc.services.wisc.edu/UWDS/WebService/NetID"> <xsd:element name="reserveNetIDFault"> <xsd:complexType><xsd:sequence><xsd:element name="Fault" type="tns:FaultType"/></xsd:sequence></xsd:complexType> </xsd:element> +<xsd:element name="setQuestions"> + <xsd:complexType> + <xsd:sequence> + <xsd:element minOccurs="1" maxOccurs="1" name="uid" type="xsd:string"/> + <xsd:element minOccurs="1" maxOccurs="1" name="Questions" type="tns:Questions"/> + </xsd:sequence> + </xsd:complexType> + + +</xsd:element> +<xsd:element name="setQuestionsResponse"> + + <xsd:complexType> + <xsd:sequence> + <xsd:element minOccurs="1" maxOccurs="1" name="result" type="xsd:integer"/> + </xsd:sequence> + </xsd:complexType> + +</xsd:element> +<xsd:element name="setQuestionsFault"> +<xsd:complexType><xsd:sequence><xsd:element name="Fault" type="tns:FaultType"/></xsd:sequence></xsd:complexType> +</xsd:element> <xsd:element name="reserveNetIDsTest"> <xsd:complexType> @@ -652,28 +697,6 @@ targetNamespace="http://rpc.services.wisc.edu/UWDS/WebService/NetID"> <xsd:element name="reserveNetIDsTestFault"> <xsd:complexType><xsd:sequence><xsd:element name="Fault" type="tns:FaultType"/></xsd:sequence></xsd:complexType> </xsd:element> -<xsd:element name="setQuestions"> - <xsd:complexType> - <xsd:sequence> - <xsd:element minOccurs="1" maxOccurs="1" name="uid" type="xsd:string"/> - <xsd:element minOccurs="1" maxOccurs="1" name="Questions" type="tns:Questions"/> - </xsd:sequence> - </xsd:complexType> - - -</xsd:element> -<xsd:element name="setQuestionsResponse"> - - <xsd:complexType> - <xsd:sequence> - <xsd:element minOccurs="1" maxOccurs="1" name="result" type="xsd:integer"/> - </xsd:sequence> - </xsd:complexType> - -</xsd:element> -<xsd:element name="setQuestionsFault"> -<xsd:complexType><xsd:sequence><xsd:element name="Fault" type="tns:FaultType"/></xsd:sequence></xsd:complexType> -</xsd:element> <xsd:element name="testMethod"> <xsd:complexType> @@ -762,6 +785,20 @@ targetNamespace="http://rpc.services.wisc.edu/UWDS/WebService/NetID"> </xsd:element> </xsd:schema> </wsdl:types> +<wsdl:message name="checkLOAInput"> +<wsdl:part name="parameters" +element="tns:checkLOA"/> +</wsdl:message> + +<wsdl:message name="checkLOAOutput"> +<wsdl:part name="parameters" +element="tns:checkLOAResponse"/> +</wsdl:message> +<wsdl:message name="checkLOAFault"> +<wsdl:part name="parameters" +element="tns:checkLOAFault"/> +</wsdl:message> + <wsdl:message name="AuthenticateInput"> <wsdl:part name="parameters" element="tns:Authenticate"/> @@ -1112,32 +1149,32 @@ element="tns:reserveNetIDResponse"/> element="tns:reserveNetIDFault"/> </wsdl:message> -<wsdl:message name="reserveNetIDsTestInput"> +<wsdl:message name="setQuestionsInput"> <wsdl:part name="parameters" -element="tns:reserveNetIDsTest"/> +element="tns:setQuestions"/> </wsdl:message> -<wsdl:message name="reserveNetIDsTestOutput"> +<wsdl:message name="setQuestionsOutput"> <wsdl:part name="parameters" -element="tns:reserveNetIDsTestResponse"/> +element="tns:setQuestionsResponse"/> </wsdl:message> -<wsdl:message name="reserveNetIDsTestFault"> +<wsdl:message name="setQuestionsFault"> <wsdl:part name="parameters" -element="tns:reserveNetIDsTestFault"/> +element="tns:setQuestionsFault"/> </wsdl:message> -<wsdl:message name="setQuestionsInput"> +<wsdl:message name="reserveNetIDsTestInput"> <wsdl:part name="parameters" -element="tns:setQuestions"/> +element="tns:reserveNetIDsTest"/> </wsdl:message> -<wsdl:message name="setQuestionsOutput"> +<wsdl:message name="reserveNetIDsTestOutput"> <wsdl:part name="parameters" -element="tns:setQuestionsResponse"/> +element="tns:reserveNetIDsTestResponse"/> </wsdl:message> -<wsdl:message name="setQuestionsFault"> +<wsdl:message name="reserveNetIDsTestFault"> <wsdl:part name="parameters" -element="tns:setQuestionsFault"/> +element="tns:reserveNetIDsTestFault"/> </wsdl:message> <wsdl:message name="testMethodInput"> @@ -1197,6 +1234,32 @@ element="tns:releaseHeldLHSFault"/> </wsdl:message> <wsdl:portType name="NetIDPortType"> +<wsdl:operation name="checkLOA"> + +<!-- + + verifies a date of birth and a campus/photoid. + + The response document consists of a result code. + + Result Codes: + + 200 - credentials good. + 400 - credentials bad. + 401 - invalid input parameters. + 402 - no PVI found for uid + 403 - no LOA found for uid + 404 - no Wiscard eligibility data found for uid + 405 - person is LOA2, missing Wiscard as input + 500 - server error + + +--> +<wsdl:input message="tns:checkLOAInput"/> +<wsdl:output message="tns:checkLOAOutput"/> +<wsdl:fault name="checkLOAFault" +message="tns:checkLOAFault"/> +</wsdl:operation> <wsdl:operation name="Authenticate"> <!-- @@ -1590,6 +1653,7 @@ message="tns:deleteIssuedLHSFault"/> Result Codes: 401 - bad args + 422 - invalid email format 501 - Error Calling Oracle Function 502 - setRecoveryEmail for $netid Failed @@ -1775,6 +1839,27 @@ message="tns:getNetIDForRecoveryEmailFault"/> <wsdl:fault name="reserveNetIDFault" message="tns:reserveNetIDFault"/> </wsdl:operation> +<wsdl:operation name="setQuestions"> + +<!-- + + Sets the password recovery questions for a UDS person. + + The response document consists of a result code. + + Result Codes: + + 200 - OK + 401 - bad parameters + 500 - oracle error + + +--> +<wsdl:input message="tns:setQuestionsInput"/> +<wsdl:output message="tns:setQuestionsOutput"/> +<wsdl:fault name="setQuestionsFault" +message="tns:setQuestionsFault"/> +</wsdl:operation> <wsdl:operation name="reserveNetIDsTest"> <!-- @@ -1798,27 +1883,6 @@ message="tns:reserveNetIDFault"/> <wsdl:fault name="reserveNetIDsTestFault" message="tns:reserveNetIDsTestFault"/> </wsdl:operation> -<wsdl:operation name="setQuestions"> - -<!-- - - Sets the password recovery questions for a UDS person. - - The response document consists of a result code. - - Result Codes: - - 200 - OK - 401 - bad parameters - 500 - oracle error - - ---> -<wsdl:input message="tns:setQuestionsInput"/> -<wsdl:output message="tns:setQuestionsOutput"/> -<wsdl:fault name="setQuestionsFault" -message="tns:setQuestionsFault"/> -</wsdl:operation> <wsdl:operation name="testMethod"> <!-- @@ -1907,6 +1971,19 @@ message="tns:releaseHeldLHSFault"/> type="tns:NetIDPortType"> <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/> +<wsdl:operation name="checkLOA"> +<soap:operation soapAction="http://rpc.services.wisc.edu/UWDS/WebService/NetID#checkLOA"/> +<wsdl:input> +<soap:body use="literal"/> +</wsdl:input> +<wsdl:output> +<soap:body use="literal"/> +</wsdl:output> +<wsdl:fault name="checkLOAFault"> +<soap:fault use="literal" +name="checkLOAFault"/> +</wsdl:fault> +</wsdl:operation> <wsdl:operation name="Authenticate"> <soap:operation soapAction="http://rpc.services.wisc.edu/UWDS/WebService/NetID#Authenticate"/> <wsdl:input> @@ -2232,30 +2309,30 @@ name="getNetIDForRecoveryEmailFault"/> name="reserveNetIDFault"/> </wsdl:fault> </wsdl:operation> -<wsdl:operation name="reserveNetIDsTest"> -<soap:operation soapAction="http://rpc.services.wisc.edu/UWDS/WebService/NetID#reserveNetIDsTest"/> +<wsdl:operation name="setQuestions"> +<soap:operation soapAction="http://rpc.services.wisc.edu/UWDS/WebService/NetID#setQuestions"/> <wsdl:input> <soap:body use="literal"/> </wsdl:input> <wsdl:output> <soap:body use="literal"/> </wsdl:output> -<wsdl:fault name="reserveNetIDsTestFault"> +<wsdl:fault name="setQuestionsFault"> <soap:fault use="literal" -name="reserveNetIDsTestFault"/> +name="setQuestionsFault"/> </wsdl:fault> </wsdl:operation> -<wsdl:operation name="setQuestions"> -<soap:operation soapAction="http://rpc.services.wisc.edu/UWDS/WebService/NetID#setQuestions"/> +<wsdl:operation name="reserveNetIDsTest"> +<soap:operation soapAction="http://rpc.services.wisc.edu/UWDS/WebService/NetID#reserveNetIDsTest"/> <wsdl:input> <soap:body use="literal"/> </wsdl:input> <wsdl:output> <soap:body use="literal"/> </wsdl:output> -<wsdl:fault name="setQuestionsFault"> +<wsdl:fault name="reserveNetIDsTestFault"> <soap:fault use="literal" -name="setQuestionsFault"/> +name="reserveNetIDsTestFault"/> </wsdl:fault> </wsdl:operation> <wsdl:operation name="testMethod"> -- GitLab