File: test_atack_protection.py

package info (click to toggle)
auth0-python 4.13.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,280 kB
  • sloc: python: 8,933; makefile: 15; sh: 2
file content (96 lines) | stat: -rw-r--r-- 3,585 bytes parent folder | download
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
92
93
94
95
96
import unittest
from unittest import mock

from ...management.attack_protection import AttackProtection


class TestAttackProtection(unittest.TestCase):
    def test_init_with_optionals(self):
        t = AttackProtection(
            domain="domain", token="jwttoken", telemetry=False, timeout=(10, 2)
        )
        self.assertEqual(t.client.options.timeout, (10, 2))
        telemetry_header = t.client.base_headers.get("Auth0-Client", None)
        self.assertEqual(telemetry_header, None)

    @mock.patch("auth0.management.attack_protection.RestClient")
    def test_get_breached_password_detection(self, mock_rc):
        mock_instance = mock_rc.return_value
        mock_instance.get.return_value = {}

        ap = AttackProtection(domain="domain", token="jwttoken")
        ap.get_breached_password_detection()

        args, kwargs = mock_instance.get.call_args

        self.assertEqual(
            "https://domain/api/v2/attack-protection/breached-password-detection",
            args[0],
        )

    @mock.patch("auth0.management.attack_protection.RestClient")
    def test_update_breached_password_detection(self, mock_rc):
        mock_instance = mock_rc.return_value
        mock_instance.patch.return_value = {}

        c = AttackProtection(domain="domain", token="jwttoken")
        c.update_breached_password_detection({"a": "b", "c": "d"})

        mock_instance.patch.assert_called_with(
            "https://domain/api/v2/attack-protection/breached-password-detection",
            data={"a": "b", "c": "d"},
        )

    @mock.patch("auth0.management.attack_protection.RestClient")
    def test_get_brute_force_protection(self, mock_rc):
        mock_instance = mock_rc.return_value
        mock_instance.get.return_value = {}

        ap = AttackProtection(domain="domain", token="jwttoken")
        ap.get_brute_force_protection()

        args, kwargs = mock_instance.get.call_args

        self.assertEqual(
            "https://domain/api/v2/attack-protection/brute-force-protection", args[0]
        )

    @mock.patch("auth0.management.attack_protection.RestClient")
    def test_update_brute_force_protection(self, mock_rc):
        mock_instance = mock_rc.return_value
        mock_instance.patch.return_value = {}

        c = AttackProtection(domain="domain", token="jwttoken")
        c.update_brute_force_protection({"a": "b", "c": "d"})

        mock_instance.patch.assert_called_with(
            "https://domain/api/v2/attack-protection/brute-force-protection",
            data={"a": "b", "c": "d"},
        )

    @mock.patch("auth0.management.attack_protection.RestClient")
    def test_get_suspicious_ip_throttling(self, mock_rc):
        mock_instance = mock_rc.return_value
        mock_instance.get.return_value = {}

        ap = AttackProtection(domain="domain", token="jwttoken")
        ap.get_suspicious_ip_throttling()

        args, kwargs = mock_instance.get.call_args

        self.assertEqual(
            "https://domain/api/v2/attack-protection/suspicious-ip-throttling", args[0]
        )

    @mock.patch("auth0.management.attack_protection.RestClient")
    def test_update_suspicious_ip_throttling(self, mock_rc):
        mock_instance = mock_rc.return_value
        mock_instance.patch.return_value = {}

        c = AttackProtection(domain="domain", token="jwttoken")
        c.update_suspicious_ip_throttling({"a": "b", "c": "d"})

        mock_instance.patch.assert_called_with(
            "https://domain/api/v2/attack-protection/suspicious-ip-throttling",
            data={"a": "b", "c": "d"},
        )