File: test_auth.py

package info (click to toggle)
python-hvac 2.3.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,800 kB
  • sloc: python: 29,360; makefile: 42; sh: 14
file content (61 lines) | stat: -rw-r--r-- 1,973 bytes parent folder | download | duplicates (2)
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
from unittest import TestCase

from tests.utils.hvac_integration_test_case import HvacIntegrationTestCase


class TestAuth(HvacIntegrationTestCase, TestCase):
    TEST_AUTH_METHOD_TYPE = "github"
    TEST_AUTH_METHOD_PATH = "test-github"

    def tearDown(self):
        self.client.sys.disable_auth_method(path=self.TEST_AUTH_METHOD_PATH)
        super().tearDown()

    def test_auth_backend_manipulation(self):
        self.assertNotIn(
            member="%s/" % self.TEST_AUTH_METHOD_PATH,
            container=self.client.sys.list_auth_methods()["data"],
        )

        self.client.sys.enable_auth_method(
            method_type=self.TEST_AUTH_METHOD_TYPE,
            path=self.TEST_AUTH_METHOD_PATH,
        )
        self.assertIn(
            member="%s/" % self.TEST_AUTH_METHOD_PATH,
            container=self.client.sys.list_auth_methods()["data"],
        )

        self.client.sys.disable_auth_method(
            path=self.TEST_AUTH_METHOD_PATH,
        )
        self.assertNotIn(
            member="%s/" % self.TEST_AUTH_METHOD_PATH,
            container=self.client.sys.list_auth_methods()["data"],
        )

    def test_tune_auth_backend(self):
        test_description = "this is a test auth backend"
        test_max_lease_ttl = 12345678
        self.client.sys.enable_auth_method(
            method_type="approle", path=self.TEST_AUTH_METHOD_PATH
        )

        expected_status_code = 204
        response = self.client.sys.tune_auth_method(
            path=self.TEST_AUTH_METHOD_PATH,
            description=test_description,
            max_lease_ttl=test_max_lease_ttl,
        )
        self.assertEqual(
            first=expected_status_code,
            second=response.status_code,
        )

        response = self.client.sys.read_auth_method_tuning(
            path=self.TEST_AUTH_METHOD_PATH
        )

        self.assertEqual(
            first=test_max_lease_ttl, second=response["data"]["max_lease_ttl"]
        )