Beispiel #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)
Beispiel #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')
Beispiel #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)
Beispiel #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')
Beispiel #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)
Beispiel #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)
Beispiel #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')
Beispiel #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')
Beispiel #9
0
 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()
Beispiel #10
0
 def identify(self, spec=None):
     '''Write out the identify response'''
     if spec:
         self.response(json.dumps(spec))
     else:
         self.response('OK')
Beispiel #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)
Beispiel #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)
Beispiel #13
0
 def identify(self, spec=None):
     '''Write out the identify response'''
     if spec:
         self.response(json.dumps(spec))
     else:
         self.response('OK')