Exemplo n.º 1
0
    def test_notify_expiring_uaa_no_results(self, redis_conn, m_divmod, m_datetime, uaac):
        """When UAA returns no results, make sure we don't do any time checking or paging"""

        redis_conn.get.return_value = None

        uaac().client_users.return_value = {'totalResults': 0, 'itemsPerPage': 100, 'resources': []}

        do_expiring_pw_notifications(app, 'http://example.org/change')
        m_datetime.strptime.assert_not_called()
        m_divmod.assert_not_called()
Exemplo n.º 2
0
    def test_does_not_notify_after_password_expired(self, redis_conn, render_template, send_email, uaac):
        """When user password has already expired, do not notify"""
        redis_conn.get.return_value = None

        passwordLastModified = (datetime.now() - timedelta(days=31)).strftime('%Y-%m-%dT%H:%M:%S.%fZ')
        val = {
            'totalResults': 1,
            'itemsPerPage': 1,
            'resources': [
                {
                    'userName': '******',
                    'passwordLastModified': passwordLastModified
                }
            ]
        }
        uaac().client_users.return_value = val

        do_expiring_pw_notifications(app, 'http://example.org/change')

        render_template.assert_not_called()
Exemplo n.º 3
0
    def test_notifies_users_when_password_is_not_yet_expired(self, redis_conn, render_template, send_email, uaac):
        """When user password expires within warning days, notify"""
        redis_conn.get.return_value = None

        passwordLastModified = (datetime.now() - timedelta(days=26)).strftime('%Y-%m-%dT%H:%M:%S.%fZ')
        val = {
            'totalResults': 1,
            'itemsPerPage': 1,
            'resources': [
                {
                    'userName': '******',
                    'passwordLastModified': passwordLastModified
                }
            ]
        }
        uaac().client_users.return_value = val

        do_expiring_pw_notifications(app, 'http://example.org/change')
        assert render_template.called
        assert render_template.call_count == 2
        assert send_email.called
        assert send_email.call_count == 1
Exemplo n.º 4
0
    def test_notify_expiring_uaa_has_results_and_handles_more_pages(self, redis_conn, uaac):
        """When When UAA does return results, do email, and paging"""

        redis_conn.get.return_value = None

        passwordLastModified = (datetime.now() - timedelta(days=31)).strftime('%Y-%m-%dT%H:%M:%S.%fZ')

        # This should give us 3 pages of results
        val = {
            'totalResults': 5,
            'itemsPerPage': 2,
            'resources': [
                {
                    'userName': '******',
                    'passwordLastModified': passwordLastModified
                },
                {
                    'userName': '******',
                    'passwordLastModified': passwordLastModified
                },
                {
                    'userName': '******',
                    'passwordLastModified': passwordLastModified
                },
                {
                    'userName': '******',
                    'passwordLastModified': passwordLastModified
                },
                {
                    'userName': '******',
                    'passwordLastModified': passwordLastModified
                }
            ]
        }
        uaac().client_users.return_value = val

        do_expiring_pw_notifications(app, 'http://example.org/change')
        assert uaac().client_users.called
        assert uaac().client_users.call_count == 3
Exemplo n.º 5
0
    def test_notify_expiring_uaa_has_results_not_enough_to_page(self, redis_conn, m_divmod, uaac):
        """When When UAA does return results, do email, but not paging because not enough results"""

        redis_conn.get.return_value = None

        passwordLastModified = (datetime.now() - timedelta(days=31)).strftime('%Y-%m-%dT%H:%M:%S.%fZ')
        val = {
            'totalResults': 1,
            'itemsPerPage': 1,
            'resources': [
                {
                    'userName': '******',
                    'passwordLastModified': passwordLastModified
                }
            ]
        }
        uaac().client_users.return_value = val

        do_expiring_pw_notifications(app, 'http://example.org/change')
        assert uaac().client_users.called
        assert uaac().client_users.call_count == 1
        m_divmod.assert_not_called()
Exemplo n.º 6
0
    def test_notify_expiring_only_runs_once_a_day(self, redis_conn, uaac):
        """When notifcations have already run once in a day, don't run again"""

        redis_conn.get.return_value = True
        do_expiring_pw_notifications(app, 'http://example.org/change')
        redis_conn.setex.assert_not_called()
Exemplo n.º 7
0
    def test_notify_expiring_no_redis_connection(self, uaac):
        """When there is no redis connection, don't even connect to UAA"""

        do_expiring_pw_notifications(app, 'http://example.org/change')
        uaac().client_users.assert_not_called()