示例#1
0
    def test_when_begin_should_send_begin_and_wait_for_ok(self):
        transport = TextReplayClientTransport('''
        C: BEGIN
        ''')
        connection = given(ADbusClientConnection().connected().with_transport(transport))

        connection.begin()

        transport.assert_story_completed()
示例#2
0
    def test_when_negotiate_unix_fd_should_send_negotiate_unix_fd_command_and_wait_for_response(self):
        transport = TextReplayClientTransport('''
        C: NEGOTIATE_UNIX_FD
        S: AGREE_UNIX_FD
        ''')
        connection = given(ADbusClientConnection().connected().with_transport(transport))

        connection.negotiate_unix_fd()

        transport.assert_story_completed()
示例#3
0
    def test_error_answer_when_request_available_mechanisms_should_raise_DbusConnectionError(self):
        transport = TextReplayClientTransport('''
        C: AUTH
        S: ERROR
        ''')
        connection = given(ADbusClientConnection().connected().with_transport(transport))

        with self.assertRaises(DbusConnectionError):
            connection.request_available_mechanisms()

        transport.assert_story_completed()
示例#4
0
    def test_server_replies_incorrectly_when_negotiate_unix_fd_should_raise_DbusConnectionError(self):
        transport = TextReplayClientTransport('''
        C: NEGOTIATE_UNIX_FD
        S: ERRO
        ''')
        connection = given(ADbusClientConnection().connected().with_transport(transport))

        with self.assertRaises(DbusConnectionError):
            connection.negotiate_unix_fd()

        transport.assert_story_completed()
示例#5
0
    def test_server_disagrees_to_unix_fd_when_unix_fd_passing_enabled_should_return_false(self):
        transport = TextReplayClientTransport('''
        C: NEGOTIATE_UNIX_FD
        S: ERROR
        ''')
        connection = given(ADbusClientConnection().connected().with_transport(transport))

        connection.negotiate_unix_fd()
        result = connection.unix_fd_passing_enabled

        transport.assert_story_completed()
        self.assertFalse(result)
示例#6
0
    def test_waiting_for_ok_when_receive_rejected_should_raise_DbusAuthenticationFailure(self):
        transport = TextReplayClientTransport('''
        C: AUTH %s
        S: REJECTED
        ''' % AFakeAuthMechanism.NAME)
        connection = given(ADbusClientConnection().connected().with_transport(transport))
        mechanism = given(AFakeAuthMechanism())

        with self.assertRaises(DbusAuthenticationFailure):
            connection.authenticate_with(mechanism)

        transport.assert_story_completed()
示例#7
0
    def test_waiting_for_ok_when_receive_ok_should_set_authenticated(self):
        transport = TextReplayClientTransport('''
        C: AUTH %s
        S: OK universal_id
        ''' % AFakeAuthMechanism.NAME)
        connection = given(ADbusClientConnection().connected().with_transport(transport))
        mechanism = given(AFakeAuthMechanism())

        connection.authenticate_with(mechanism)

        transport.assert_story_completed()
        self.assertTrue(connection.authenticated)
示例#8
0
    def test_waiting_for_data_when_receive_rejected_should_raise_DbusAuthenticationFailure(self):
        another_mechanism = 'MAGIC_COOKIE'
        transport = TextReplayClientTransport('''
        C: AUTH %s
        S: REJECTED %s
        ''' % (AFakeAuthMechanism.NAME, another_mechanism))
        connection = given(ADbusClientConnection().connected().with_transport(transport))
        mechanism = given(AFakeAuthMechanism().with_any_challenge())

        with self.assertRaises(DbusAuthenticationFailure):
            connection.authenticate_with(mechanism)

        transport.assert_story_completed()
示例#9
0
    def test_when_authenticate_should_use_initial_response_from_mechanism(self):
        a_mechanism_name = 'MAGIC_COOKIE'
        an_initial_response = '3138363935333137393635383634'
        transport = TextReplayClientTransport('''
        C: AUTH %s %s
        S: OK universal_id
        ''' % (a_mechanism_name, an_initial_response))
        connection = given(ADbusClientConnection().connected().with_transport(transport))
        mechanism = FakeAuthMechanism(a_mechanism_name, an_initial_response)

        connection.authenticate_with(mechanism)

        transport.assert_story_completed()
示例#10
0
    def test_waiting_for_data_when_receive_data_should_challenge_mechanism(self):
        a_challenge = ('8799cabb2ea93e', '8ac876e8f68ee9809bfa876e6f9876g8fa8e76e98f')
        transport = TextReplayClientTransport('''
        C: AUTH %s
        S: DATA %s
        C: DATA %s
        S: OK universal_id
        ''' % (AFakeAuthMechanism.NAME, a_challenge[0], a_challenge[1]))
        connection = given(ADbusClientConnection().connected().with_transport(transport))
        mechanism = given(AFakeAuthMechanism().with_challenges([a_challenge]))

        connection.authenticate_with(mechanism)

        transport.assert_story_completed()
示例#11
0
    def test_when_request_available_mechanisms_should_return_available_mechanisms(self):
        mechanisms = ['KERBEROS_V4', 'SKEY']
        transport = TextReplayClientTransport('''
        C: AUTH
        S: REJECTED %s
        ''' % ' '.join(mechanisms))
        connection = given(ADbusClientConnection().connected().with_transport(transport))

        result = connection.request_available_mechanisms()

        transport.assert_story_completed()
        for mechanism in mechanisms:
            self.assertIn(mechanism, result)
        self.assertEqual(len(mechanisms), len(result))
示例#12
0
    def test_waiting_for_data_when_receive_error_should_send_cancel_and_wait_for_reject(self):
        transport = TextReplayClientTransport('''
        C: AUTH %s
        S: ERROR
        C: CANCEL
        S: REJECTED
        ''' % AFakeAuthMechanism.NAME)
        connection = given(ADbusClientConnection().connected().with_transport(transport))
        mechanism = given(AFakeAuthMechanism().with_any_challenge())

        with self.assertRaises(DbusAuthenticationFailure):
            connection.authenticate_with(mechanism)

        transport.assert_story_completed()
示例#13
0
    def test_waiting_for_reject_when_receive_anything_else_should_raise_DbusConnectionError_and_disconnect(self):
        transport = TextReplayClientTransport('''
        C: AUTH %s
        S: ERROR msg
        C: CANCEL
        S: HELLOWHOISTHERE
        ''' % AFakeAuthMechanism.NAME)
        connection = given(ADbusClientConnection().connected().with_transport(transport))
        mechanism = given(AFakeAuthMechanism())

        with self.assertRaises(DbusConnectionError):
            connection.authenticate_with(mechanism)

        transport.assert_closed()
        transport.assert_story_completed()