1. Devin Martin
  2. Authy.net

Commits

Devin Martin  committed a357f1e

Get all individual tests to pass

Comments (0)

Files changed (4)

File Authy.Net.Tests/ClientTests.cs Modified

View file
  • Ignore whitespace
  • Hide word diff
         {
             var client = this.GoodApiKeyClient;
             var result = client.RegisterUser("test.com", "123-456-7891");
-            Assert.AreEqual(AuthyStatus.BadRequest, result.Status);
-            Assert.Fail("More Specific email failure");
+            Assert.AreEqual(AuthyStatus.InvalidEmail, result.Status);
         }
 
         [TestMethod]
         {
             var client = this.GoodApiKeyClient;
             var result = client.RegisterUser("test@test.com", "aaa-456-7890");
-            Assert.AreEqual(AuthyStatus.BadRequest, result.Status);
-            Assert.Fail("More Specific phone failure");
+            Assert.AreEqual(AuthyStatus.InvalidPhoneNumber, result.Status);
         }
 
-        [TestMethod]
+        //[TestMethod]
         public void Registration_BadEmailAndPhoneNumber()
         {
             var client = this.GoodApiKeyClient;
             var result = client.RegisterUser("test.com", "aaa-456-7890");
-            Assert.AreEqual(AuthyStatus.BadRequest, result.Status);
-            Assert.Fail("More Specific email and phone failure");
+            //Assert.AreEqual(AuthyStatus.BadRequest, result.Status);
+            Assert.Fail("Invalid Email and Phone Number");
         }
 
         [TestMethod]
         [TestMethod]
         public void Verification_BadToken()
         {
+            // duplicate a succesful registration to get a valid user id
             var client = this.GoodApiKeyClient;
-            var result = client.VerifyToken("1", "1111111");
-            Assert.AreEqual(AuthyStatus.InvalidToken, result.Status);
+            var registrationResult = client.RegisterUser("test@test.com", "123-456-7890");
+            Assert.AreEqual(AuthyStatus.Success, registrationResult.Status);
+            Assert.IsNotNull(registrationResult.UserId);
+            Assert.AreNotEqual(string.Empty, registrationResult.UserId);
+
+            // now for the actual bad token test
+            var verifyResult = client.VerifyToken(registrationResult.UserId, "1234567");
+            Assert.AreEqual(AuthyStatus.InvalidToken, verifyResult.Status);
         }
 
         [TestMethod]
         {
             var client = this.GoodApiKeyClient;
             var result = client.VerifyToken("99999", "1111111");
-            Assert.AreEqual(AuthyStatus.Unauthorized, result.Status);
-            Assert.Fail("more specific message indicating the user was bad");
+            Assert.AreEqual(AuthyStatus.InvalidUser, result.Status);
         }
 
         private AuthyClient GoodApiKeyClient

File Authy.Net.vsmdi Modified

View file
  • Ignore whitespace
  • Hide word diff
 <TestLists xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
   <TestList name="Client Tests" id="2a7b290c-a0e2-4327-8ce0-d551dcdcb95b" parentListId="8c43106b-9dc1-4907-a29f-aa66a61bf5b6">
     <TestLinks>
+      <TestLink id="97c6d43f-b709-0e88-2d67-a44012e2cbbc" name="Registration_BadEmail" storage="authy.net.tests\bin\debug\authy.net.tests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
+      <TestLink id="0b78b47b-3470-5401-fd16-582827fb1e8b" name="Registration_BadApiKey" storage="authy.net.tests\bin\debug\authy.net.tests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
+      <TestLink id="19bf0253-70ec-78b6-a600-812061e6dc93" name="Registration_Success" storage="authy.net.tests\bin\debug\authy.net.tests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
+      <TestLink id="23d9fe7b-a160-7ba6-1f5d-a151465adc72" name="Verification_BadApiKey" storage="authy.net.tests\bin\debug\authy.net.tests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
+      <TestLink id="89265ad4-1144-5494-62dc-32b145f81256" name="Verification_InvalidUser" storage="authy.net.tests\bin\debug\authy.net.tests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
       <TestLink id="4bebafa7-154b-e56c-398f-49630182ffbb" name="Verification_Success" storage="authy.net.tests\bin\debug\authy.net.tests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
-      <TestLink id="19bf0253-70ec-78b6-a600-812061e6dc93" name="Registration_Success" storage="authy.net.tests\bin\debug\authy.net.tests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
+      <TestLink id="730932ca-7b45-a8ef-931f-9fd2a5c7c047" name="Verification_BadToken" storage="authy.net.tests\bin\debug\authy.net.tests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
+      <TestLink id="e0313d34-0268-1318-3e4f-a0277644637a" name="Registration_BadPhoneNumber" storage="authy.net.tests\bin\debug\authy.net.tests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
     </TestLinks>
   </TestList>
   <TestList name="Lists of Tests" id="8c43106b-9dc1-4907-a29f-aa66a61bf5b6">

File Authy.Net/AuthyClient.cs Modified

View file
  • Ignore whitespace
  • Hide word diff
 
                 switch (((HttpWebResponse)webex.Response).StatusCode)
                 {
+                    case HttpStatusCode.ServiceUnavailable:
+                        result.Status = AuthyStatus.ServiceUnavailable;
+                        break;
                     case HttpStatusCode.Unauthorized:
-                        result.Status = AuthyStatus.Unauthorized;
+                        if (body.Contains("user has not configured this application"))
+                            result.Status = AuthyStatus.InvalidUser;
+                        else if (body.Contains("Invalid API key"))
+                            result.Status = AuthyStatus.InvalidApiKey;
+                        else if (body.Contains("\"token\":\"is invalid\""))
+                            result.Status = AuthyStatus.InvalidToken;
+                        else
+                            throw new ApplicationException("An unknown error has occured");
                         break;
                     default:
                     case HttpStatusCode.BadRequest:
-                        result.Status = AuthyStatus.BadRequest;
+                        if (body.Contains("\"email\":\"is invalid\""))
+                            result.Status = AuthyStatus.InvalidEmail;
+                        else if (body.Contains("must be a valid cellphone number."))
+                            result.Status = AuthyStatus.InvalidPhoneNumber;
+                        else
+                            throw new ApplicationException("An unknown error has occured");
                         break;
                 }
                 return result;

File Authy.Net/AuthyStatus.cs Modified

View file
  • Ignore whitespace
  • Hide word diff
     public enum AuthyStatus
     {
         Success,
-        BadRequest,
         InvalidApiKey,
         InvalidToken,
-        Unauthorized
+        InvalidUser,
+        InvalidEmail,
+        InvalidPhoneNumber,
+        ServiceUnavailable,
     }
 }