예제 #1
0
 def test_identify(self):
     '''The connection sends the identify commands'''
     expected = ''.join([
         constants.MAGIC_V2, constants.IDENTIFY, constants.NL,
         util.pack(json.dumps(self.connection._identify_options))
     ])
     self.assertEqual(self.socket.read(), expected)
예제 #2
0
 def test_auth_required_provided(self):
     '''Sends the auth message if required and provided'''
     res = response.Response(self.connection, response.Response.FRAME_TYPE,
                             json.dumps({'auth_required': True}))
     with mock.patch.object(self.connection, 'auth') as mock_auth:
         with mock.patch.object(self.connection, '_auth_secret', 'hello'):
             self.connection.identified(res)
             mock_auth.assert_called_with('hello')
예제 #3
0
 def test_tls_unsupported(self):
     '''Raises an exception if the server does not support TLS'''
     res = response.Response(self.connection, response.Response.FRAME_TYPE,
                             json.dumps({'tls_v1': False}))
     options = {'tls_v1': True}
     with mock.patch.object(self.connection, '_identify_options', options):
         self.assertRaises(exceptions.UnsupportedException,
                           self.connection.identified, res)
예제 #4
0
 def test_auth_required_provided(self):
     '''Sends the auth message if required and provided'''
     res = response.Response(self.connection, response.Response.FRAME_TYPE,
         json.dumps({'auth_required': True}))
     with mock.patch.object(self.connection, 'auth') as mock_auth:
         with mock.patch.object(self.connection, '_auth_secret', 'hello'):
             self.connection.identified(res)
             mock_auth.assert_called_with('hello')
예제 #5
0
 def test_tls_unsupported(self):
     '''Raises an exception if the server does not support TLS'''
     res = response.Response(self.connection,
         response.Response.FRAME_TYPE, json.dumps({'tls_v1': False}))
     options = {'tls_v1': True}
     with mock.patch.object(self.connection, '_identify_options', options):
         self.assertRaises(exceptions.UnsupportedException,
             self.connection.identified, res)
예제 #6
0
 def test_identify(self):
     '''The connection sends the identify commands'''
     expected = ''.join([
         constants.MAGIC_V2,
         constants.IDENTIFY,
         constants.NL,
         util.pack(json.dumps(self.connection._identify_options))])
     self.assertEqual(self.socket.read(), expected)
예제 #7
0
 def test_auth_provided_not_required(self):
     '''Logs a warning if you provide auth when none is required'''
     res = response.Response(self.connection, response.Response.FRAME_TYPE,
                             json.dumps({'auth_required': False}))
     with mock.patch('nsq.connection.logger') as mock_logger:
         with mock.patch.object(self.connection, '_auth_secret', 'hello'):
             self.connection.identified(res)
             mock_logger.warn.assert_called_with(
                 'Authentication secret provided but not required')
예제 #8
0
 def test_auth_provided_not_required(self):
     '''Logs a warning if you provide auth when none is required'''
     res = response.Response(self.connection, response.Response.FRAME_TYPE,
         json.dumps({'auth_required': False}))
     with mock.patch('nsq.connection.logger') as mock_logger:
         with mock.patch.object(self.connection, '_auth_secret', 'hello'):
             self.connection.identified(res)
             mock_logger.warn.assert_called_with(
                 'Authentication secret provided but not required')
예제 #9
0
파일: common.py 프로젝트: kossack/nsq-py
 def identify(self, identify=None):
     '''Consume the magic and identify messages'''
     for server in self.servers:
         server.assertMagic()
         server.readIdentify()
         # We'll also send the optional identify response or 'OK'
         if identify:
             server.response(json.dumps(identify))
         else:
             server.response('OK')
     # And now the client should read any messages it has received
     yield self.client.read()
예제 #10
0
 def identify(self, spec=None):
     '''Write out the identify response'''
     if spec:
         self.response(json.dumps(spec))
     else:
         self.response('OK')
예제 #11
0
 def test_auth_required_not_provided(self):
     '''Raises an exception if auth is required but not provided'''
     res = response.Response(self.connection, response.Response.FRAME_TYPE,
                             json.dumps({'auth_required': True}))
     self.assertRaises(exceptions.UnsupportedException,
                       self.connection.identified, res)
예제 #12
0
 def test_auth_required_not_provided(self):
     '''Raises an exception if auth is required but not provided'''
     res = response.Response(self.connection, response.Response.FRAME_TYPE,
         json.dumps({'auth_required': True}))
     self.assertRaises(exceptions.UnsupportedException,
         self.connection.identified, res)
예제 #13
0
 def identify(self, spec=None):
     '''Write out the identify response'''
     if spec:
         self.response(json.dumps(spec))
     else:
         self.response('OK')