def test_correct_url_used_for_report_ready(self):
     self.find_endpoint.return_value = 'test_endpoint'
     shim = wa_shim()
     shim.register_with_azure_and_fetch_data()
     expected_url = 'http://test_endpoint/machine?comp=health'
     self.assertEqual(
         [mock.call(expected_url, data=mock.ANY, extra_headers=mock.ANY)],
         self.AzureEndpointHttpClient.return_value.post.call_args_list)
 def test_failure_to_fetch_goalstate_bubbles_up(self):
     class SentinelException(Exception):
         pass
     self.AzureEndpointHttpClient.return_value.get.side_effect = (
         SentinelException)
     shim = wa_shim()
     self.assertRaises(SentinelException,
                       shim.register_with_azure_and_fetch_data)
 def test_certificates_used_to_determine_public_keys(self):
     shim = wa_shim()
     data = shim.register_with_azure_and_fetch_data()
     self.assertEqual(
         [mock.call(self.GoalState.return_value.certificates_xml)],
         self.OpenSSLManager.return_value.parse_certificates.call_args_list)
     self.assertEqual(
         self.OpenSSLManager.return_value.parse_certificates.return_value,
         data['public-keys'])
 def test_goal_state_values_used_for_report_ready(self):
     self.GoalState.return_value.incarnation = 'TestIncarnation'
     self.GoalState.return_value.container_id = 'TestContainerId'
     self.GoalState.return_value.instance_id = 'TestInstanceId'
     shim = wa_shim()
     shim.register_with_azure_and_fetch_data()
     posted_document = (
         self.AzureEndpointHttpClient.return_value.post.call_args[1]['data']
     )
     self.assertIn('TestIncarnation', posted_document)
     self.assertIn('TestContainerId', posted_document)
     self.assertIn('TestInstanceId', posted_document)
 def test_correct_url_used_for_goalstate(self):
     self.find_endpoint.return_value = 'test_endpoint'
     shim = wa_shim()
     shim.register_with_azure_and_fetch_data()
     get = self.AzureEndpointHttpClient.return_value.get
     self.assertEqual(
         [mock.call('http://test_endpoint/machine/?comp=goalstate')],
         get.call_args_list)
     self.assertEqual(
         [mock.call(get.return_value.contents,
                    self.AzureEndpointHttpClient.return_value)],
         self.GoalState.call_args_list)
 def test_certificates_used_to_determine_public_keys(self):
     shim = wa_shim()
     """if register_with_azure_and_fetch_data() isn't passed some info about
        the user's public keys, there's no point in even trying to parse
        the certificates
     """
     mypk = [{'fingerprint': 'fp1', 'path': 'path1'},
             {'fingerprint': 'fp3', 'path': 'path3', 'value': ''}]
     certs = {'fp1': 'expected-key',
              'fp2': 'should-not-be-found',
              'fp3': 'expected-no-value-key',
              }
     sslmgr = self.OpenSSLManager.return_value
     sslmgr.parse_certificates.return_value = certs
     data = shim.register_with_azure_and_fetch_data(pubkey_info=mypk)
     self.assertEqual(
         [mock.call(self.GoalState.return_value.certificates_xml)],
         sslmgr.parse_certificates.call_args_list)
     self.assertIn('expected-key', data['public-keys'])
     self.assertIn('expected-no-value-key', data['public-keys'])
     self.assertNotIn('should-not-be-found', data['public-keys'])
 def test_clean_up_will_clean_up_openssl_manager_if_instantiated(self):
     shim = wa_shim()
     shim.register_with_azure_and_fetch_data()
     shim.clean_up()
     self.assertEqual(
         1, self.OpenSSLManager.return_value.clean_up.call_count)
 def test_clean_up_can_be_called_at_any_time(self):
     shim = wa_shim()
     shim.clean_up()
 def test_absent_certificates_produces_empty_public_keys(self):
     mypk = [{'fingerprint': 'fp1', 'path': 'path1'}]
     self.GoalState.return_value.certificates_xml = None
     shim = wa_shim()
     data = shim.register_with_azure_and_fetch_data(pubkey_info=mypk)
     self.assertEqual([], data['public-keys'])
 def test_http_client_uses_certificate(self):
     shim = wa_shim()
     shim.register_with_azure_and_fetch_data()
     self.assertEqual(
         [mock.call(self.OpenSSLManager.return_value.certificate)],
         self.AzureEndpointHttpClient.call_args_list)
Example #11
0
 def test_http_client_does_not_use_certificate(self):
     shim = wa_shim()
     shim.register_with_azure_and_fetch_data()
     self.assertEqual(
         [mock.call(None)],
         self.AzureEndpointHttpClient.call_args_list)