Skip to content

Commit

Permalink
sync: Fix Content-Type logic bug, add test (#1412)
Browse files Browse the repository at this point in the history
  • Loading branch information
russellhancox committed Aug 8, 2024
1 parent b1cf83a commit 341abf0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Source/santasyncservice/SNTSyncStage.mm
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ - (NSMutableURLRequest *)requestWithMessage:(google::protobuf::Message *)message
}

- (NSMutableURLRequest *)requestWithData:(NSData *)requestBody contentType:(NSString *)contentType {
if (contentType.length) contentType = @"application/octet-stream";
if (!contentType.length) contentType = @"application/octet-stream";

NSMutableURLRequest *req = [[NSMutableURLRequest alloc] initWithURL:[self stageURL]];
[req setHTTPMethod:@"POST"];
Expand Down
20 changes: 11 additions & 9 deletions Source/santasyncservice/SNTSyncTest.mm
Original file line number Diff line number Diff line change
Expand Up @@ -280,15 +280,17 @@ - (void)testPreflightBasicResponse {
SNTSyncPreflight *sut = [[SNTSyncPreflight alloc] initWithState:self.syncState];

NSData *respData = [self dataFromFixture:@"sync_preflight_basic.json"];
[self stubRequestBody:respData
response:nil
error:nil
validateBlock:^BOOL(NSURLRequest *req) {
NSData *gotReqData = [req HTTPBody];
NSData *expectedReqData = [self dataFromFixture:@"sync_preflight_request.json"];
XCTAssertEqualObjects(gotReqData, expectedReqData);
return YES;
}];
[self
stubRequestBody:respData
response:nil
error:nil
validateBlock:^BOOL(NSURLRequest *req) {
NSData *gotReqData = [req HTTPBody];
NSData *expectedReqData = [self dataFromFixture:@"sync_preflight_request.json"];
XCTAssertEqualObjects(gotReqData, expectedReqData);
XCTAssertEqualObjects([req valueForHTTPHeaderField:@"Content-Type"], @"application/json");
return YES;
}];

XCTAssertTrue([sut sync]);
XCTAssertEqual(self.syncState.clientMode, SNTClientModeMonitor);
Expand Down

0 comments on commit 341abf0

Please sign in to comment.