diff options
author | Jorge Canizales <jcanizales@google.com> | 2015-06-12 19:15:18 -0700 |
---|---|---|
committer | Jorge Canizales <jcanizales@google.com> | 2015-06-13 01:30:34 -0700 |
commit | d7981253de93fcfd3666a3e3bd1714b2f66a448b (patch) | |
tree | 7d1aa13895f7a913c1bda7e96dd8b37ee8ab2f57 | |
parent | d666fd068bfcd37461c73354f5dc2fdc2b8f72b0 (diff) |
Add test to set and read headers. Flaky!!
-rw-r--r-- | src/objective-c/tests/GRPCClientTests.m | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/objective-c/tests/GRPCClientTests.m b/src/objective-c/tests/GRPCClientTests.m index 4f4fe591e8..917e637d68 100644 --- a/src/objective-c/tests/GRPCClientTests.m +++ b/src/objective-c/tests/GRPCClientTests.m @@ -144,4 +144,35 @@ static GRPCMethodName *kUnaryCallMethod; [self waitForExpectationsWithTimeout:2. handler:nil]; } +- (void)testMetadata { + __weak XCTestExpectation *expectation = [self expectationWithDescription:@"RPC unauthorized."]; + + RMTSimpleRequest *request = [RMTSimpleRequest message]; + request.fillUsername = YES; + request.fillOauthScope = YES; + id<GRXWriter> requestsWriter = [GRXWriter writerWithValue:[request data]]; + + GRPCCall *call = [[GRPCCall alloc] initWithHost:kHostAddress + method:kUnaryCallMethod + requestsWriter:requestsWriter]; + + call.requestMetadata = [NSMutableDictionary dictionaryWithDictionary: + @{@"Authorization": @"Bearer bogusToken"}]; + + id<GRXWriteable> responsesWriteable = [[GRXWriteable alloc] initWithValueHandler:^(NSData *value) { + XCTFail(@"Received unexpected response: %@", value); + } completionHandler:^(NSError *errorOrNil) { + XCTAssertNotNil(errorOrNil, @"Finished without error!"); + XCTAssertEqual(errorOrNil.code, 16, @"Finished with unexpected error: %@", errorOrNil); + NSString *challengeHeader = call.responseMetadata[@"www-authenticate"][0]; + XCTAssertGreaterThan(challengeHeader.length, 0, + @"No challenge in response headers %@", call.responseMetadata); + [expectation fulfill]; + }]; + + [call startWithWriteable:responsesWriteable]; + + [self waitForExpectationsWithTimeout:2. handler:nil]; +} + @end |