File: test_auth_methods.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 (75 lines) | stat: -rw-r--r-- 2,363 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
from unittest import TestCase

import requests_mock

from hvac import Client


class TestAuthMethods(TestCase):
    """Tests for methods related to Vault sys/auth routes."""

    @requests_mock.Mocker()
    def test_tune_auth_backend(self, requests_mocker):
        expected_status_code = 204
        test_mount_point = "approle-test"
        test_description = "this is a test description"
        requests_mocker.register_uri(
            method="POST",
            url=f"http://localhost:8200/v1/sys/auth/{test_mount_point}/tune",
            status_code=expected_status_code,
        )
        client = Client()
        actual_response = client.sys.tune_auth_method(
            path=test_mount_point,
            description=test_description,
        )

        self.assertEqual(
            first=expected_status_code,
            second=actual_response.status_code,
        )

        actual_request_params = requests_mocker.request_history[0].json()

        # Ensure we sent through an optional tune parameter as expected
        self.assertEqual(
            first=test_description,
            second=actual_request_params["description"],
        )

    @requests_mock.Mocker()
    def test_get_auth_backend_tuning(self, requests_mocker):
        expected_status_code = 200
        test_mount_point = "approle-test"
        mock_response = {
            "max_lease_ttl": 12345678,
            "lease_id": "",
            "force_no_cache": False,
            "warnings": None,
            "data": {
                "force_no_cache": False,
                "default_lease_ttl": 2764800,
                "max_lease_ttl": 12345678,
            },
            "wrap_info": None,
            "auth": None,
            "lease_duration": 0,
            "request_id": "673f2336-3235-b988-2194-c68261a02bfe",
            "default_lease_ttl": 2764800,
            "renewable": False,
        }
        requests_mocker.register_uri(
            method="GET",
            url=f"http://localhost:8200/v1/sys/auth/{test_mount_point}/tune",
            status_code=expected_status_code,
            json=mock_response,
        )
        client = Client()
        actual_response = client.sys.read_auth_method_tuning(
            path=test_mount_point,
        )

        self.assertEqual(
            first=mock_response,
            second=actual_response,
        )