From d7981253de93fcfd3666a3e3bd1714b2f66a448b Mon Sep 17 00:00:00 2001
From: Jorge Canizales <jcanizales@google.com>
Date: Fri, 12 Jun 2015 19:15:18 -0700
Subject: [PATCH] Add test to set and read headers. Flaky!!

---
 src/objective-c/tests/GRPCClientTests.m | 31 +++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

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
-- 
GitLab