Пример #1
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()
Пример #2
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)
Пример #3
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()
Пример #4
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()
Пример #5
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()
Пример #6
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()