Skip to content

Commit 1fa85ec

Browse files
committed
[YouTube] Add tests for signature timestamp extraction and signature deobfuscation function extraction and execution
1 parent a04bc32 commit 1fa85ec

1 file changed

Lines changed: 53 additions & 0 deletions

File tree

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package org.schabi.newpipe.extractor.services.youtube;
2+
3+
import org.junit.jupiter.api.BeforeEach;
4+
import org.junit.jupiter.params.ParameterizedTest;
5+
import org.junit.jupiter.params.provider.CsvSource;
6+
import org.junit.jupiter.params.provider.ValueSource;
7+
import org.schabi.newpipe.downloader.DownloaderTestImpl;
8+
import org.schabi.newpipe.extractor.NewPipe;
9+
10+
import javax.annotation.Nonnull;
11+
import java.io.IOException;
12+
13+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
14+
import static org.junit.jupiter.api.Assertions.assertTrue;
15+
16+
class YoutubeSignaturesTest {
17+
18+
@BeforeEach
19+
void setUp() throws IOException {
20+
NewPipe.init(DownloaderTestImpl.getInstance());
21+
YoutubeTestsUtils.ensureStateless();
22+
}
23+
24+
@ValueSource(strings = {
25+
"QzUGs1qRTEI",
26+
""
27+
})
28+
@ParameterizedTest
29+
void testSignatureTimestampExtraction(@Nonnull final String videoId) throws Exception {
30+
final Integer signatureTimestamp =
31+
YoutubeJavaScriptPlayerManager.getSignatureTimestamp(videoId);
32+
assertTrue(signatureTimestamp > 0, "signatureTimestamp is <= 0");
33+
}
34+
35+
/*
36+
The first column of the CSV entries is a video ID
37+
The second one of these entries are not real signatures, but as the deobfuscation function
38+
manipulates strings, we can use random characters combined as strings to test the extraction
39+
and the execution of the function
40+
*/
41+
@CsvSource(value = {
42+
"QzUGs1qRTEI,5QjJrWzVcOutYYNyxkDJVkzQDZQxNbbxGi4hRoh2h4PomQMQq9vo2WPHVpHgxRn7qT3WyhRiJa1k1t1DL3lynZtupHmG3wW4qh59faKjtY4UVu",
43+
",7vIK4hG6NbcIEQP4ZIRjonOzuPHh7wTrEgBdEMYyfE4F5Pq0FiGdv04kptb587c8aToH345ETJ8dMbXnpOmjanP3nzgJ0iNg8oHIm8oeQODPSP"
44+
})
45+
@ParameterizedTest
46+
void testSignatureDeobfuscation(@Nonnull final String videoId,
47+
@Nonnull final String sampleString) throws Exception {
48+
// As the signature deobfuscation changes frequently with player versions, we can only test
49+
// that we get a different string than the original one
50+
assertNotEquals(sampleString,
51+
YoutubeJavaScriptPlayerManager.deobfuscateSignature(videoId, sampleString));
52+
}
53+
}

0 commit comments

Comments
 (0)