Exemplo n.º 1
0
    def test_no_newline_in_received_header(self):
        non_zero_port = 1
        sock = mock.MagicMock()

        header_without_newline = ''
        sock.recv(6).decode = mock.MagicMock(
            name='decode', return_value=header_without_newline)

        with mock.patch('oauth2client.contrib.devshell.os') as os_mod:
            os_mod.getenv = mock.MagicMock(name='getenv',
                                           return_value=non_zero_port)
            with mock.patch('oauth2client.contrib.devshell.socket') as socket:
                socket.socket = mock.MagicMock(name='socket',
                                               return_value=sock)
                with self.assertRaises(CommunicationError):
                    _SendRecv()
                os_mod.getenv.assert_called_once_with(DEVSHELL_ENV, 0)
                socket.socket.assert_called_once_with()
                sock.recv(6).decode.assert_called_once_with()

                data = CREDENTIAL_INFO_REQUEST_JSON
                msg = _to_bytes('{0}\n{1}'.format(len(data), data),
                                encoding='utf-8')
                expected_sock_calls = [
                    mock.call.recv(6),  # From the set-up above
                    mock.call.connect(('localhost', non_zero_port)),
                    mock.call.sendall(msg),
                    mock.call.recv(6),
                    mock.call.recv(6),  # From the check above
                ]
                self.assertEqual(sock.method_calls, expected_sock_calls)
Exemplo n.º 2
0
    def test_no_newline_in_received_header(self):
        non_zero_port = 1
        sock = mock.Mock()

        header_without_newline = ''
        sock.recv(6).decode = mock.Mock(name='decode',
                                        return_value=header_without_newline)

        with mock.patch('oauth2client.contrib.devshell.os') as os_mod:
            os_mod.getenv = mock.Mock(name='getenv',
                                      return_value=non_zero_port)
            with mock.patch('oauth2client.contrib.devshell.socket') as socket:
                socket.socket = mock.Mock(name='socket', return_value=sock)
                with self.assertRaises(devshell.CommunicationError):
                    devshell._SendRecv()
                os_mod.getenv.assert_called_once_with(devshell.DEVSHELL_ENV, 0)
                socket.socket.assert_called_once_with()
                sock.recv(6).decode.assert_called_once_with()

                data = devshell.CREDENTIAL_INFO_REQUEST_JSON
                msg = _helpers._to_bytes('{0}\n{1}'.format(len(data), data),
                                         encoding='utf-8')
                expected_sock_calls = [
                    mock.call.recv(6),  # From the set-up above
                    mock.call.connect(('localhost', non_zero_port)),
                    mock.call.sendall(msg),
                    mock.call.recv(6),
                    mock.call.recv(6),  # From the check above
                ]
                self.assertEqual(sock.method_calls, expected_sock_calls)
Exemplo n.º 3
0
 def test_port_zero(self):
     with mock.patch('oauth2client.contrib.devshell.os') as os_mod:
         os_mod.getenv = mock.MagicMock(name='getenv', return_value=0)
         with self.assertRaises(NoDevshellServer):
             _SendRecv()
         os_mod.getenv.assert_called_once_with(DEVSHELL_ENV, 0)
Exemplo n.º 4
0
 def test_request_response(self):
     with _AuthReferenceServer():
         response = _SendRecv()
         self.assertEqual(response.user_email, '*****@*****.**')
         self.assertEqual(response.project_id, 'fooproj')
         self.assertEqual(response.access_token, 'sometoken')
Exemplo n.º 5
0
 def test_port_zero(self):
     with mock.patch('oauth2client.contrib.devshell.os') as os_mod:
         os_mod.getenv = mock.Mock(name='getenv', return_value=0)
         with self.assertRaises(devshell.NoDevshellServer):
             devshell._SendRecv()
         os_mod.getenv.assert_called_once_with(devshell.DEVSHELL_ENV, 0)
Exemplo n.º 6
0
 def test_request_response(self):
     with _AuthReferenceServer():
         response = devshell._SendRecv()
         self.assertEqual(response.user_email, '*****@*****.**')
         self.assertEqual(response.project_id, 'fooproj')
         self.assertEqual(response.access_token, 'sometoken')