Browse Source

Requests with invalid credentials should terminate with a 401 code

As defined in RFC 7235 https://tools.ietf.org/html/rfc7235#section-3.1

Fixes #1159
Cédric Luthi 9 years ago
parent
commit
b5b7339e16
2 changed files with 7 additions and 13 deletions
  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 {
             } else {
                 if challenge.previousFailureCount > 0 {
                 if challenge.previousFailureCount > 0 {
-                    disposition = .CancelAuthenticationChallenge
+                    disposition = .RejectProtectionSpace
                 } else {
                 } else {
                     credential = self.credential ?? session.configuration.URLCredentialStorage?.defaultCredentialForProtectionSpace(challenge.protectionSpace)
                     credential = self.credential ?? session.configuration.URLCredentialStorage?.defaultCredentialForProtectionSpace(challenge.protectionSpace)
 
 

+ 6 - 12
Tests/AuthenticationTests.swift

@@ -84,13 +84,10 @@ class BasicAuthenticationTestCase: AuthenticationTestCase {
 
 
         // Then
         // Then
         XCTAssertNotNil(request, "request should not be nil")
         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(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() {
     func testHTTPBasicAuthenticationWithValidCredentials() {
@@ -160,13 +157,10 @@ class HTTPDigestAuthenticationTestCase: AuthenticationTestCase {
 
 
         // Then
         // Then
         XCTAssertNotNil(request, "request should not be nil")
         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(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() {
     func testHTTPDigestAuthenticationWithValidCredentials() {