Przeglądaj źródła

Merge pull request #1164 from 0xced/invalid-credentials-401

Requests with invalid credentials should terminate with a 401 code
Christian Noon 9 lat temu
rodzic
commit
c3983bc140
2 zmienionych plików z 7 dodań i 13 usunięć
  1. 1 1
      Source/Request.swift
  2. 6 12
      Tests/AuthenticationTests.swift

+ 1 - 1
Source/Request.swift

@@ -284,7 +284,7 @@ public class Request {
                 }
             } else {
                 if challenge.previousFailureCount > 0 {
-                    disposition = .CancelAuthenticationChallenge
+                    disposition = .RejectProtectionSpace
                 } else {
                     credential = self.credential ?? session.configuration.URLCredentialStorage?.defaultCredentialForProtectionSpace(challenge.protectionSpace)
 

+ 6 - 12
Tests/AuthenticationTests.swift

@@ -84,13 +84,10 @@ class BasicAuthenticationTestCase: AuthenticationTestCase {
 
         // Then
         XCTAssertNotNil(request, "request should not be nil")
-        XCTAssertNil(response, "response should be nil")
+        XCTAssertNotNil(response, "response should not be nil")
+        XCTAssertEqual(response?.statusCode ?? 0, 401, "response status code should be 401")
         XCTAssertNotNil(data, "data should not be nil")
-        XCTAssertNotNil(error, "error should not be nil")
-
-        if let code = error?.code {
-            XCTAssertEqual(code, -999, "error should be NSURLErrorDomain Code -999 'cancelled'")
-        }
+        XCTAssertNil(error, "error should be nil")
     }
 
     func testHTTPBasicAuthenticationWithValidCredentials() {
@@ -160,13 +157,10 @@ class HTTPDigestAuthenticationTestCase: AuthenticationTestCase {
 
         // Then
         XCTAssertNotNil(request, "request should not be nil")
-        XCTAssertNil(response, "response should be nil")
+        XCTAssertNotNil(response, "response should not be nil")
+        XCTAssertEqual(response?.statusCode ?? 0, 401, "response status code should be 401")
         XCTAssertNotNil(data, "data should not be nil")
-        XCTAssertNotNil(error, "error should not be nil")
-
-        if let code = error?.code {
-            XCTAssertEqual(code, -999, "error should be NSURLErrorDomain Code -999 'cancelled'")
-        }
+        XCTAssertNil(error, "error should be nil")
     }
 
     func testHTTPDigestAuthenticationWithValidCredentials() {