зеркало из https://github.com/github/AFNetworking.git
Adding test for connection:willSendRequestForAuthenticationChallenge:.
This commit is contained in:
Родитель
41d228f3a7
Коммит
fd7dd13e23
|
@ -25,6 +25,10 @@
|
|||
25C4EC42173D86B60083E116 /* MobileCoreServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 25C4EC30173D7DCA0083E116 /* MobileCoreServices.framework */; };
|
||||
29A9CE2117456336002360C8 /* AFJSONRequestOperationTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 29A9CE2017456336002360C8 /* AFJSONRequestOperationTests.m */; };
|
||||
29A9CE2217456336002360C8 /* AFJSONRequestOperationTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 29A9CE2017456336002360C8 /* AFJSONRequestOperationTests.m */; };
|
||||
A7DC62A617592E4200EBEC2F /* AFTestURLProtocol.m in Sources */ = {isa = PBXBuildFile; fileRef = A7DC62A517592E4200EBEC2F /* AFTestURLProtocol.m */; };
|
||||
A7DC62A717592E4200EBEC2F /* AFTestURLProtocol.m in Sources */ = {isa = PBXBuildFile; fileRef = A7DC62A517592E4200EBEC2F /* AFTestURLProtocol.m */; };
|
||||
A7DC62A917592E4800EBEC2F /* AFURLConnectionOperationTests.m in Sources */ = {isa = PBXBuildFile; fileRef = A7DC62A817592E4800EBEC2F /* AFURLConnectionOperationTests.m */; };
|
||||
A7DC62AA17592E4800EBEC2F /* AFURLConnectionOperationTests.m in Sources */ = {isa = PBXBuildFile; fileRef = A7DC62A817592E4800EBEC2F /* AFURLConnectionOperationTests.m */; };
|
||||
AC11A74923B64A3096ACADFC /* libPods-osx.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 96A923755B00464187DEDBAF /* libPods-osx.a */; };
|
||||
F8C6F282174D2C6200B154D5 /* Icon.png in Resources */ = {isa = PBXBuildFile; fileRef = F8C6F281174D2C6200B154D5 /* Icon.png */; };
|
||||
F8C6F283174D2C6200B154D5 /* Icon.png in Resources */ = {isa = PBXBuildFile; fileRef = F8C6F281174D2C6200B154D5 /* Icon.png */; };
|
||||
|
@ -74,6 +78,9 @@
|
|||
2B6D24F8E1B74E10A269E8B3 /* libPods.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libPods.a; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
55E73C267F33406A9F92476C /* libPods-ios.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-ios.a"; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
96A923755B00464187DEDBAF /* libPods-osx.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-osx.a"; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
A7DC62A417592E4200EBEC2F /* AFTestURLProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AFTestURLProtocol.h; sourceTree = "<group>"; };
|
||||
A7DC62A517592E4200EBEC2F /* AFTestURLProtocol.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AFTestURLProtocol.m; sourceTree = "<group>"; };
|
||||
A7DC62A817592E4800EBEC2F /* AFURLConnectionOperationTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AFURLConnectionOperationTests.m; sourceTree = "<group>"; };
|
||||
F8C6F281174D2C6200B154D5 /* Icon.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = Icon.png; path = ../Example/Icon.png; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
|
@ -188,11 +195,14 @@
|
|||
25801548173EB3B00026AA6E /* Tests */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
A7DC62A417592E4200EBEC2F /* AFTestURLProtocol.h */,
|
||||
A7DC62A517592E4200EBEC2F /* AFTestURLProtocol.m */,
|
||||
2580153E173EB3A70026AA6E /* AFNetworkingTests.h */,
|
||||
2580153F173EB3A70026AA6E /* AFNetworkingTests.m */,
|
||||
2580153B173EB3A70026AA6E /* AFHTTPRequestOperationTests.m */,
|
||||
29A9CE2017456336002360C8 /* AFJSONRequestOperationTests.m */,
|
||||
2580153A173EB3A70026AA6E /* AFHTTPClientTests.m */,
|
||||
A7DC62A817592E4800EBEC2F /* AFURLConnectionOperationTests.m */,
|
||||
);
|
||||
name = Tests;
|
||||
sourceTree = "<group>";
|
||||
|
@ -328,6 +338,8 @@
|
|||
25801542173EB3A70026AA6E /* AFHTTPRequestOperationTests.m in Sources */,
|
||||
25801546173EB3A70026AA6E /* AFNetworkingTests.m in Sources */,
|
||||
29A9CE2117456336002360C8 /* AFJSONRequestOperationTests.m in Sources */,
|
||||
A7DC62A617592E4200EBEC2F /* AFTestURLProtocol.m in Sources */,
|
||||
A7DC62A917592E4800EBEC2F /* AFURLConnectionOperationTests.m in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
@ -339,6 +351,8 @@
|
|||
25801543173EB3A70026AA6E /* AFHTTPRequestOperationTests.m in Sources */,
|
||||
25801547173EB3A70026AA6E /* AFNetworkingTests.m in Sources */,
|
||||
29A9CE2217456336002360C8 /* AFJSONRequestOperationTests.m in Sources */,
|
||||
A7DC62A717592E4200EBEC2F /* AFTestURLProtocol.m in Sources */,
|
||||
A7DC62AA17592E4800EBEC2F /* AFURLConnectionOperationTests.m in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
// Prefix header for all source files of the 'AFNetworking' target in the 'AFNetworking' project
|
||||
//
|
||||
|
||||
#define _AFNETWORKING_PIN_SSL_CERTIFICATES_
|
||||
|
||||
#ifdef __OBJC__
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
// AFTestURLProtocol.h
|
||||
//
|
||||
// Copyright (c) 2011 Gowalla (http://gowalla.com/)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
|
||||
|
||||
/**
|
||||
@abstract <#abstract comment#>
|
||||
*/
|
||||
@interface AFTestURLProtocol : NSURLProtocol <NSURLAuthenticationChallengeSender>
|
||||
|
||||
+ (void)matchURL:(NSURL *)URL withCallback:(id(^)(AFTestURLProtocol *protocol))initializationCallback;
|
||||
|
||||
@end
|
|
@ -0,0 +1,98 @@
|
|||
// AFTestURLProtocol.m
|
||||
//
|
||||
// Copyright (c) 2011 Gowalla (http://gowalla.com/)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
#import "AFTestURLProtocol.h"
|
||||
|
||||
typedef id(^AFTestURLProtocolInitializationCallback)(AFTestURLProtocol *protocol);
|
||||
static NSURL *matchingURL = nil;
|
||||
static AFTestURLProtocolInitializationCallback initializationCallback = NULL;
|
||||
|
||||
|
||||
|
||||
@implementation AFTestURLProtocol
|
||||
|
||||
+ (void)matchURL:(NSURL *)URL withCallback:(id(^)(AFTestURLProtocol *protocol))callback {
|
||||
matchingURL = URL;
|
||||
initializationCallback = callback;
|
||||
}
|
||||
|
||||
+ (void)load {
|
||||
[NSURLProtocol registerClass:[AFTestURLProtocol class]];
|
||||
}
|
||||
|
||||
#pragma mark - NSURLProtocol
|
||||
|
||||
+ (BOOL)canInitWithRequest:(NSURLRequest *)request {
|
||||
return [request.URL isEqual:matchingURL] && initializationCallback;
|
||||
}
|
||||
|
||||
+ (NSURLRequest *)canonicalRequestForRequest:(NSURLRequest *)request {
|
||||
return request;
|
||||
}
|
||||
|
||||
+ (BOOL)requestIsCacheEquivalent:(NSURLRequest *)a toRequest:(NSURLRequest *)b {
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (id)initWithRequest:(NSURLRequest *)request cachedResponse:(NSCachedURLResponse *)cachedResponse client:(id<NSURLProtocolClient>)client {
|
||||
NSParameterAssert(initializationCallback);
|
||||
|
||||
if (self = [super initWithRequest:request cachedResponse:cachedResponse client:client]) {
|
||||
self = initializationCallback(self);
|
||||
|
||||
matchingURL = nil;
|
||||
initializationCallback = NULL;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)startLoading {
|
||||
|
||||
}
|
||||
|
||||
- (void)stopLoading {
|
||||
|
||||
}
|
||||
|
||||
#pragma mark - NSURLAuthenticationChallengeSender
|
||||
|
||||
- (void)useCredential:(NSURLCredential *)credential forAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
|
||||
|
||||
}
|
||||
|
||||
- (void)continueWithoutCredentialForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
|
||||
|
||||
}
|
||||
|
||||
- (void)cancelAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
|
||||
|
||||
}
|
||||
|
||||
- (void)performDefaultHandlingForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
|
||||
|
||||
}
|
||||
|
||||
- (void)rejectProtectionSpaceAndContinueWithChallenge:(NSURLAuthenticationChallenge *)challenge {
|
||||
|
||||
}
|
||||
|
||||
@end
|
|
@ -0,0 +1,60 @@
|
|||
//
|
||||
// AFJSONRequestOperationTests.m
|
||||
// AFNetworking Tests
|
||||
//
|
||||
// Created by Kevin Harwood on 5/16/13.
|
||||
// Copyright (c) 2013 AFNetworking. All rights reserved.
|
||||
//
|
||||
|
||||
#import "AFNetworkingTests.h"
|
||||
#import "AFURLConnectionOperation.h"
|
||||
#import "AFTestURLProtocol.h"
|
||||
#import "OCMock.h"
|
||||
|
||||
@interface AFURLConnectionOperationTests : SenTestCase
|
||||
|
||||
@property (readwrite, nonatomic, strong) NSURL *baseURL;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
|
||||
@implementation AFURLConnectionOperationTests
|
||||
@synthesize baseURL = _baseURL;
|
||||
|
||||
- (void)setUp {
|
||||
self.baseURL = [NSURL URLWithString:AFNetworkingTestsBaseURLString];
|
||||
}
|
||||
|
||||
- (void)testThatAFURLConnectionOperationInvokesWillSendRequestForAuthenticationChallengeBlock {
|
||||
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"/path" relativeToURL:self.baseURL]];
|
||||
AFURLConnectionOperation *operation = [[AFURLConnectionOperation alloc] initWithRequest:request];
|
||||
|
||||
__block BOOL willSendRequestForAuthenticationChallengeBlockInvoked = NO;
|
||||
[operation setWillSendRequestForAuthenticationChallengeBlock:^(NSURLConnection *connection, NSURLAuthenticationChallenge *challenge) {
|
||||
willSendRequestForAuthenticationChallengeBlockInvoked = YES;
|
||||
}];
|
||||
|
||||
[AFTestURLProtocol matchURL:request.URL withCallback:^id(AFTestURLProtocol *protocol) {
|
||||
id mockedProtocol = [OCMockObject partialMockForObject:protocol];
|
||||
|
||||
void(^startOperation)(NSInvocation *invocation) = ^(NSInvocation *invocation) {
|
||||
__unsafe_unretained AFTestURLProtocol *protocol = nil;
|
||||
[invocation getArgument:&protocol atIndex:0];
|
||||
|
||||
NSURLProtectionSpace *protectionSpace = [[NSURLProtectionSpace alloc] initWithHost:request.URL.host port:request.URL.port.integerValue protocol:request.URL.scheme realm:nil authenticationMethod:NSURLAuthenticationMethodDefault];
|
||||
NSURLAuthenticationChallenge *authenticationChallenge = [[NSURLAuthenticationChallenge alloc] initWithProtectionSpace:protectionSpace proposedCredential:nil previousFailureCount:0 failureResponse:nil error:nil sender:protocol];
|
||||
[protocol.client URLProtocol:protocol didReceiveAuthenticationChallenge:authenticationChallenge];
|
||||
};
|
||||
[[[mockedProtocol stub] andDo:startOperation] startLoading];
|
||||
|
||||
return mockedProtocol;
|
||||
}];
|
||||
|
||||
[operation start];
|
||||
expect(willSendRequestForAuthenticationChallengeBlockInvoked).will.beTruthy();
|
||||
|
||||
[operation cancel];
|
||||
}
|
||||
|
||||
@end
|
Загрузка…
Ссылка в новой задаче