File: temp_password_test.py

package info (click to toggle)
python-irodsclient 3.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,352 kB
  • sloc: python: 16,650; xml: 525; sh: 104; awk: 5; sql: 3; makefile: 3
file content (92 lines) | stat: -rw-r--r-- 2,724 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
#! /usr/bin/env python

import os
import sys
import unittest
from irods.exception import UserDoesNotExist
from irods.session import iRODSSession
import irods.test.helpers as helpers


class TestTempPassword(unittest.TestCase):
    """Suite of tests for setting and getting temporary passwords as rodsadmin or rodsuser"""

    admin = None
    new_user = "bobby"
    password = "foobar"

    @classmethod
    def setUpClass(cls):
        cls.admin = helpers.make_session()

    @classmethod
    def tearDownClass(cls):
        cls.admin.cleanup()

    def test_temp_password(self):
        # Make a new user
        self.admin.users.create(self.new_user, "rodsuser")
        self.admin.users.modify(self.new_user, "password", self.password)

        # Login as the new test user, to retrieve a temporary password
        with iRODSSession(
            host=self.admin.host,
            port=self.admin.port,
            user=self.new_user,
            password=self.password,
            zone=self.admin.zone,
        ) as session:
            # Obtain the temporary password
            conn = session.pool.get_connection()
            temp_password = conn.temp_password()

        # Open a new session with the temporary password
        with iRODSSession(
            host=self.admin.host,
            port=self.admin.port,
            user=self.new_user,
            password=temp_password,
            zone=self.admin.zone,
        ) as session:

            # do something that connects to the server
            session.users.get(self.admin.username)

        # delete new user
        self.admin.users.remove(self.new_user)

        # user should be gone
        with self.assertRaises(UserDoesNotExist):
            self.admin.users.get(self.new_user)

    def test_set_temp_password(self):
        # make a new user
        temp_user = self.admin.users.create(self.new_user, "rodsuser")

        # obtain a temporary password as rodsadmin for another user
        temp_password = temp_user.temp_password()

        # open a session as the new user
        with iRODSSession(
            host=self.admin.host,
            port=self.admin.port,
            user=self.new_user,
            password=temp_password,
            zone=self.admin.zone,
        ) as session:

            # do something that connects to the server
            session.users.get(self.new_user)

        # delete new user
        self.admin.users.remove(self.new_user)

        # user should be gone
        with self.assertRaises(UserDoesNotExist):
            self.admin.users.get(self.new_user)


if __name__ == "__main__":
    # let the tests find the parent irods lib
    sys.path.insert(0, os.path.abspath("../.."))
    unittest.main()