Exemplo n.º 1
0
    def testRaisesWhenInitializedFromInvalidValues(self):
        with self.assertRaises(ValueError):
            client_plugin.ApiClientId("blah")

        with self.assertRaises(ValueError):
            client_plugin.ApiClientId("C.0")

        with self.assertRaises(ValueError):
            client_plugin.ApiClientId("C." + "0" * 15)

        with self.assertRaises(ValueError):
            client_plugin.ApiClientId("C." + "1" * 16 + "/foo")
    def setUp(self):
        super(CheckClientLabelsTest, self).setUp()
        self.client_urn = self.SetupClient(0)
        self.client_id = api_client.ApiClientId(self.client_urn.Basename())

        self.labels_whitelist = ["foo"]
        self.labels_owners_whitelist = ["GRR"]
Exemplo n.º 3
0
    def testResolvesSimpleFlowURN(self):
        flow_urn = flow.GRRFlow.StartFlow(
            flow_name=flow_test_lib.FlowWithOneNestedFlow.__name__,
            client_id=self.client_urn,
            token=self.token)
        flow_id = flow_plugin.ApiFlowId(flow_urn.Basename())

        self.assertEqual(
            flow_id.ResolveClientFlowURN(client_plugin.ApiClientId(
                self.client_urn),
                                         token=self.token), flow_urn)
Exemplo n.º 4
0
    def testLeavesClientIdEmptyForNonClientBasedFlows(self):
        client_id = self.SetupClients(1)[0]
        flow_urn = flow.GRRFlow.StartFlow(
            client_id=client_id,
            flow_name=processes.ListProcesses.__name__,
            token=self.token)
        flow_obj = aff4.FACTORY.Open(flow_urn, token=self.token)
        flow_api_obj = flow_plugin.ApiFlow().InitFromAff4Object(
            flow_obj, flow_id=flow_urn.Basename())

        self.assertEquals(flow_api_obj.client_id,
                          client_plugin.ApiClientId(client_id))
Exemplo n.º 5
0
  def testResolvesHuntFlowURN(self):
    self._StartHunt()

    client_flows_urns = list(
        aff4.FACTORY.ListChildren(self.client_urn.Add("flows")))
    self.assertEqual(len(client_flows_urns), 1)

    flow_id = flow_plugin.ApiFlowId(client_flows_urns[0].Basename())
    self.assertEqual(
        flow_id.ResolveClientFlowURN(
            client_plugin.ApiClientId(self.client_urn), token=self.token),
        client_flows_urns[0])
Exemplo n.º 6
0
    def testResolvesNestedFlowURN(self):
        flow_urn = flow.GRRFlow.StartFlow(
            flow_name=flow_test_lib.FlowWithOneNestedFlow.__name__,
            client_id=self.client_urn,
            token=self.token)

        children = list(
            aff4.FACTORY.MultiOpen(list(aff4.FACTORY.ListChildren(flow_urn)),
                                   aff4_type=flow.GRRFlow,
                                   token=self.token))
        self.assertEqual(len(children), 1)

        flow_id = flow_plugin.ApiFlowId(flow_urn.Basename() + "/" +
                                        children[0].urn.Basename())
        self.assertEqual(
            flow_id.ResolveClientFlowURN(client_plugin.ApiClientId(
                self.client_urn),
                                         token=self.token), children[0].urn)
Exemplo n.º 7
0
  def testResolvesNestedHuntFlowURN(self):
    self._StartHunt()

    client_flows_urns = list(
        aff4.FACTORY.ListChildren(self.client_urn.Add("flows")))
    self.assertEqual(len(client_flows_urns), 1)

    flow_fd = aff4.FACTORY.Open(client_flows_urns[0], token=self.token)
    nested_flows_urns = list(flow_fd.ListChildren())
    nested_flows = list(
        aff4.FACTORY.MultiOpen(
            nested_flows_urns, aff4_type=flow.GRRFlow, token=self.token))
    self.assertEqual(len(nested_flows), 1)

    flow_id = flow_plugin.ApiFlowId(
        client_flows_urns[0].Basename() + "/" + nested_flows[0].urn.Basename())
    self.assertEqual(
        flow_id.ResolveClientFlowURN(
            client_plugin.ApiClientId(self.client_urn), token=self.token),
        nested_flows[0].urn)
Exemplo n.º 8
0
    def testConvertsToClientURN(self):
        client_id = client_plugin.ApiClientId("C." + "1" * 16)
        client_urn = client_id.ToClientURN()

        self.assertEqual(client_urn.Basename(), client_id)
        self.assertEqual(client_urn, "aff4:/C." + "1" * 16)
Exemplo n.º 9
0
 def testRaisesWhenToClientURNCalledOnUninitializedValue(self):
     client_id = client_plugin.ApiClientId()
     with self.assertRaises(ValueError):
         client_id.ToClientURN()
Exemplo n.º 10
0
 def GenerateSample(self, number=0):
     return client_plugin.ApiClientId("C.%016d" % number)