Beispiel #1
0
    def test_update_service_metadata_async_different(self):
        self.mock_metadata_entity()
        self.mock(net, 'json_request_async', mock.Mock())
        dict = {
            'version': '1.0',
            'validation': {
                'url':
                'https://a.com/different_validate',
                'patterns': [
                    {
                        'config_set': 'projects/bar',
                        'path': 'foo.cfg'
                    },
                    {
                        'config_set': 'regex:services/.+',
                        'path': 'regex:.+'
                    },
                ]
            }
        }

        net.json_request_async.return_value = future(dict)
        self.mock(logging, 'info', mock.Mock())
        mock_service = mock.Mock()
        mock_service.id = 'deadbeef'
        mock_service.metadata_url = 'https://a.com/validate'
        services._update_service_metadata_async(mock_service).get_result()
        self.assertTrue(logging.info.called)
Beispiel #2
0
  def test_update_service_metadata_async_same(self):
    self.mock_metadata_entity()
    self.mock(net, 'json_request_async', mock.Mock())
    dct = {
      'version': '1.0',
      'validation': {
        'url': 'https://a.com/validate',
        'patterns': [
          {'config_set': 'projects/foo', 'path': 'bar.cfg'},
          {'config_set': 'regex:services/.+', 'path': 'regex:.+'},
        ]
      }
    }

    net.json_request_async.return_value = future(dct)
    self.mock(logging, 'info', mock.Mock())
    services._update_service_metadata_async(self.service_proto()).get_result()
    self.assertFalse(logging.info.called)

    net.json_request_async.assert_called_once_with(
        'https://a.com/metadata',
        method='GET',
        payload=None,
        scopes=net.EMAIL_SCOPE,
        use_jwt_auth=False,
        audience=None)
  def test_update_service_metadata_async_jwt(self):
    self.mock_metadata_entity()
    self.mock(net, 'json_request_async', mock.Mock())
    dct = {
      'version': '1.0',
      'validation': {
        'url': 'https://a.com/validate',
        'patterns': [
          {'config_set': 'projects/foo', 'path': 'bar.cfg'},
          {'config_set': 'regex:services/.+', 'path': 'regex:.+'},
        ]
      }
    }

    net.json_request_async.return_value = future(dct)
    self.mock(logging, 'info', mock.Mock())
    svc = self.service_proto(
        jwt_auth=service_config_pb2.Service.JWTAuth(
            audience='https://service.example.com'))
    services._update_service_metadata_async(svc).get_result()
    self.assertFalse(logging.info.called)

    net.json_request_async.assert_called_once_with(
        'https://a.com/metadata',
        method='GET',
        payload=None,
        deadline=50,
        scopes=None,
        use_jwt_auth=True,
        audience='https://service.example.com')
Beispiel #4
0
 def test_update_service_metadata_no_service_url(self):
     self.mock_metadata_entity()
     mock_service = mock.Mock()
     mock_service.id = 'deadbeef'
     mock_service.metadata_url = ''
     self.mock(logging, 'info', mock.Mock())
     services._update_service_metadata_async(mock_service).get_result()
     self.assertTrue(logging.info.called)
Beispiel #5
0
 def test_update_service_metadata_no_service_url(self):
   self.mock_metadata_entity()
   self.mock(logging, 'info', mock.Mock())
   svc = self.service_proto(metadata_url='')
   services._update_service_metadata_async(svc).get_result()
   self.assertTrue(logging.info.called)