Skip to content

Commit

Permalink
Add unit test for broken signature function
Browse files Browse the repository at this point in the history
Skip URLs when signature unscrambling fails in order to get proper restricted playback error (XCDYouTubeErrorRestrictedPlayback) instead of media player playback error caused by an invalid stream URL (missing signature).
  • Loading branch information
0xced committed Jul 17, 2014
1 parent 869b722 commit c9e9e0b
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 0 deletions.

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions XCDYouTubeKit Tests/XCDYouTubeProtectedVideosTestCase.m
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,20 @@ - (void) testProtectedVideoWithoutSignatureFunction
XCTAssertTrue([monitor waitWithTimeout:10]);
}

// Edit testProtectedVideoWithBrokenSignatureFunction.json by returning null in the signature function
- (void) testProtectedVideoWithBrokenSignatureFunction
{
TRVSMonitor *monitor = [TRVSMonitor monitor];
[[XCDYouTubeClient defaultClient] getVideoWithIdentifier:@"Pgum6OT_VH8" completionHandler:^(XCDYouTubeVideo *video, NSError *error) {
XCTAssertNil(video);
XCTAssertEqualObjects(error.domain, XCDYouTubeVideoErrorDomain);
XCTAssertEqual(error.code, XCDYouTubeErrorRestrictedPlayback);
XCTAssertEqualObjects(error.localizedDescription, @"This video contains content from WMG. It is restricted from playback on certain sites. Watch on YouTube");
[monitor signal];
}];
XCTAssertTrue([monitor waitWithTimeout:10]);
}

// Edit testProtectedVideoWithoutJavaScriptPlayerURL.json by replacing `\"js\":` with `\"xs\":`
- (void) testProtectedVideoWithoutJavaScriptPlayerURL
{
Expand Down
2 changes: 2 additions & 0 deletions XCDYouTubeKit/XCDYouTubeVideo.m
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ - (instancetype) initWithIdentifier:(NSString *)identifier info:(NSDictionary *)

NSString *scrambledSignature = stream[@"s"];
NSString *signature = [playerScript unscrambleSignature:scrambledSignature];
if (playerScript && !signature)
continue;

NSString *urlString = stream[@"url"];
NSString *itag = stream[@"itag"];
Expand Down

0 comments on commit c9e9e0b

Please sign in to comment.