'Test the http response to unknown clients.'

def testEnrollment(self):

    self.server_communicator.client_cache.Flush()
    self.client = aff4.FACTORY.Create(self.client_cn, aff4_grr.VFSGRRClient, mode='rw', token=self.token)
    self.client.DeleteAttribute(self.client.Schema.CERT)
    self.client.Flush()
    self.SendToServer()
    status = self.client_communicator.RunOnce()
    self.assertEqual(status.code, 406)
    self.assertEqual(len(self.messages), 10)
    self.assertEqual(self.messages[0].auth_state, rdf_flows.GrrMessage.AuthorizationState.UNAUTHENTICATED)
    status = self.client_communicator.RunOnce()
    self.assertEqual(len(self.messages), 11)
    self.assertEqual(self.messages[(-1)].session_id, ca_enroller.Enroler.well_known_session_id)
    flow_obj = ca_enroller.Enroler(ca_enroller.Enroler.well_known_session_id, mode='rw', token=self.token)
    flow_obj.ProcessMessage(self.messages[(-1)])
    status = self.client_communicator.RunOnce()
    self.assertEqual(status.code, 200)
    self.client = aff4.FACTORY.Create(self.client_cn, aff4_grr.VFSGRRClient, mode='rw', token=self.token)
    self.assertTrue(self.client.Get(self.client.Schema.CERT))
    self.SendToServer()
    status = self.client_communicator.RunOnce()
    self.assertEqual(status.code, 200)
