File size: 2,182 Bytes
f7e59f8
 
 
 
 
 
 
 
82321d6
efe24a6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39acdce
 
 
9e555f0
 
79befd6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
642bb0a
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import pytest

from pytube import cipher
from pytube.exceptions import RegexMatchError


def test_map_functions():
    with pytest.raises(RegexMatchError):
        cipher.map_functions("asdf")


def test_get_initial_function_name_with_no_match_should_error():
    with pytest.raises(RegexMatchError):
        cipher.get_initial_function_name("asdf")


def test_get_transform_object_with_no_match_should_error():
    with pytest.raises(RegexMatchError):
        cipher.get_transform_object("asdf", var="lt")


def test_reverse():
    reversed_array = cipher.reverse([1, 2, 3, 4], None)
    assert reversed_array == [4, 3, 2, 1]


def test_splice():
    assert cipher.splice([1, 2, 3, 4], 2) == [3, 4]
    assert cipher.splice([1, 2, 3, 4], 1) == [2, 3, 4]


def test_throttling_reverse():
    a = [1, 2, 3, 4]
    cipher.throttling_reverse(a)
    assert a == [4, 3, 2, 1]


def test_throttling_push():
    a = [1, 2, 3, 4]
    cipher.throttling_push(a, 5)
    assert a == [1, 2, 3, 4, 5]


def test_throttling_unshift():
    a = [1, 2, 3, 4]
    cipher.throttling_unshift(a, 2)
    assert a == [3, 4, 1, 2]


def test_throttling_nested_splice():
    a = [1, 2, 3, 4]
    cipher.throttling_nested_splice(a, 2)
    assert a == [3, 2, 1, 4]
    cipher.throttling_nested_splice(a, 0)
    assert a == [3, 2, 1, 4]


def test_throttling_prepend():
    a = [1, 2, 3, 4]
    cipher.throttling_prepend(a, 1)
    assert a == [4, 1, 2, 3]
    a = [1, 2, 3, 4]
    cipher.throttling_prepend(a, 2)
    assert a == [3, 4, 1, 2]


def test_throttling_swap():
    a = [1, 2, 3, 4]
    cipher.throttling_swap(a, 3)
    assert a == [4, 2, 3, 1]


def test_js_splice():
    mapping = {

    }
    for args, result in mapping.items():
        a = [1, 2, 3, 4]
        assert cipher.js_splice(a, *args) == result


def test_get_throttling_function_name(base_js):
    # Values expected as of 2022/02/04:
    raw_var = r'var Apa=[hha]'
    assert raw_var in base_js
    raw_code = r'a.url="";a.C&&(b=a.get("n"))&&(b=Apa[0](b),a.set("n",b),'\
               r'Apa.length||hha(""))}};'
    assert raw_code in base_js
    func_name = cipher.get_throttling_function_name(base_js)
    assert func_name == "hha"