def Run(self): client_urn = self.SetupClient(0) client_id = client_urn.Basename() acl_test_lib.CreateUser(self.token.username) # Create a running mock refresh operation. running_flow_id = self.CreateMultiGetFileFlow( client_urn, file_path="fs/os/c/bin/bash", token=self.token) # Create a mock refresh operation and complete it. finished_flow_id = self.CreateMultiGetFileFlow( client_urn, file_path="fs/os/c/bin/bash", token=self.token) if data_store.RelationalDBFlowsEnabled(): flow_base.TerminateFlow(client_id, finished_flow_id, reason="Fake Error") # Create an arbitrary flow to check on 404s. non_update_flow_id = flow.StartFlow( client_id=client_id, flow_cls=discovery.Interrogate) else: finished_flow_urn = client_urn.Add("flows").Add(finished_flow_id) with aff4.FACTORY.Open( finished_flow_urn, aff4_type=flow.GRRFlow, mode="rw", token=self.token) as flow_obj: flow_obj.GetRunner().Error("Fake error") # Create an arbitrary flow to check on 404s. non_update_flow_id = flow.StartAFF4Flow( client_id=client_urn, flow_name=discovery.Interrogate.__name__, token=self.token).Basename() # Unkonwn flow ids should also cause 404s. unknown_flow_id = "F:12345678" # Check both operations. self.Check( "GetVfsFileContentUpdateState", args=vfs_plugin.ApiGetVfsFileContentUpdateStateArgs( client_id=client_id, operation_id=running_flow_id), replace={running_flow_id: "W:ABCDEF"}) self.Check( "GetVfsFileContentUpdateState", args=vfs_plugin.ApiGetVfsFileContentUpdateStateArgs( client_id=client_id, operation_id=finished_flow_id), replace={finished_flow_id: "W:ABCDEF"}) self.Check( "GetVfsFileContentUpdateState", args=vfs_plugin.ApiGetVfsFileContentUpdateStateArgs( client_id=client_id, operation_id=non_update_flow_id), replace={non_update_flow_id: "W:ABCDEF"}) self.Check( "GetVfsFileContentUpdateState", args=vfs_plugin.ApiGetVfsFileContentUpdateStateArgs( client_id=client_id, operation_id=unknown_flow_id), replace={unknown_flow_id: "W:ABCDEF"})
def testHandlerReturnsCorrectStateForFlow(self): # Create a mock refresh operation. flow_id = self.CreateMultiGetFileFlow( self.client_id, file_path="fs/os/c/bin/bash", token=self.token) args = vfs_plugin.ApiGetVfsFileContentUpdateStateArgs( client_id=self.client_id, operation_id=flow_id) # Flow was started and should be running. result = self.handler.Handle(args, token=self.token) self.assertEqual(result.state, "RUNNING") # Terminate flow. if data_store.RelationalDBFlowsEnabled(): flow_base.TerminateFlow(self.client_id.Basename(), flow_id, "Fake error") else: flow_urn = self.client_id.Add("flows").Add(flow_id) with aff4.FACTORY.Open( flow_urn, aff4_type=flow.GRRFlow, mode="rw", token=self.token) as flow_obj: flow_obj.GetRunner().Error("Fake error") # Recheck status and see if it changed. result = self.handler.Handle(args, token=self.token) self.assertEqual(result.state, "FINISHED")
def Run(self): client_id = self.SetupClient(0) acl_test_lib.CreateUser(self.token.username) # Create a running mock refresh operation. self.running_flow_urn = self.CreateMultiGetFileFlow( client_id, file_path="fs/os/c/bin/bash", token=self.token) # Create a mock refresh operation and complete it. self.finished_flow_urn = self.CreateMultiGetFileFlow( client_id, file_path="fs/os/c/bin/bash", token=self.token) with aff4.FACTORY.Open(self.finished_flow_urn, aff4_type=flow.GRRFlow, mode="rw", token=self.token) as flow_obj: flow_obj.GetRunner().Error("Fake error") # Create an arbitrary flow to check on 404s. self.non_update_flow_urn = flow.StartFlow( client_id=client_id, flow_name=discovery.Interrogate.__name__, token=self.token) # Unkonwn flow ids should also cause 404s. self.unknown_flow_id = "F:12345678" # Check both operations. self.Check("GetVfsFileContentUpdateState", args=vfs_plugin.ApiGetVfsFileContentUpdateStateArgs( client_id=client_id.Basename(), operation_id=str(self.running_flow_urn)), replace={self.running_flow_urn.Basename(): "W:ABCDEF"}) self.Check("GetVfsFileContentUpdateState", args=vfs_plugin.ApiGetVfsFileContentUpdateStateArgs( client_id=client_id.Basename(), operation_id=str(self.finished_flow_urn)), replace={self.finished_flow_urn.Basename(): "W:ABCDEF"}) self.Check("GetVfsFileContentUpdateState", args=vfs_plugin.ApiGetVfsFileContentUpdateStateArgs( client_id=client_id.Basename(), operation_id=str(self.non_update_flow_urn)), replace={self.non_update_flow_urn.Basename(): "W:ABCDEF"}) self.Check("GetVfsFileContentUpdateState", args=vfs_plugin.ApiGetVfsFileContentUpdateStateArgs( client_id=client_id.Basename(), operation_id=str(self.unknown_flow_id)), replace={self.unknown_flow_id: "W:ABCDEF"})
def Run(self): client_id = self.SetupClient(0) acl_test_lib.CreateUser(self.test_username) # Create a running mock refresh operation. running_flow_id = self.CreateMultiGetFileFlow( client_id, file_path="fs/os/c/bin/bash") # Create a mock refresh operation and complete it. finished_flow_id = self.CreateMultiGetFileFlow( client_id, file_path="fs/os/c/bin/bash") flow_base.TerminateFlow(client_id, finished_flow_id, reason="Fake Error") # Create an arbitrary flow to check on 404s. non_update_flow_id = flow.StartFlow( client_id=client_id, flow_cls=discovery.Interrogate) # Unknown flow ids should also cause 404s. unknown_flow_id = "F:12345678" # Check both operations. self.Check( "GetVfsFileContentUpdateState", args=vfs_plugin.ApiGetVfsFileContentUpdateStateArgs( client_id=client_id, operation_id=running_flow_id), replace={running_flow_id: "ABCDEF"}) self.Check( "GetVfsFileContentUpdateState", args=vfs_plugin.ApiGetVfsFileContentUpdateStateArgs( client_id=client_id, operation_id=finished_flow_id), replace={finished_flow_id: "ABCDEF"}) self.Check( "GetVfsFileContentUpdateState", args=vfs_plugin.ApiGetVfsFileContentUpdateStateArgs( client_id=client_id, operation_id=non_update_flow_id), replace={non_update_flow_id: "ABCDEF"}) self.Check( "GetVfsFileContentUpdateState", args=vfs_plugin.ApiGetVfsFileContentUpdateStateArgs( client_id=client_id, operation_id=unknown_flow_id), replace={unknown_flow_id: "ABCDEF"})
def testHandlerRaisesOnArbitraryFlowId(self): # Create a mock flow. flow_id = flow.StartFlow( client_id=self.client_id, flow_cls=discovery.Interrogate) args = vfs_plugin.ApiGetVfsFileContentUpdateStateArgs( client_id=self.client_id, operation_id=flow_id) # Our mock flow is not a MultiGetFile flow, so an error should be raised. with self.assertRaises(vfs_plugin.VfsFileContentUpdateNotFoundError): self.handler.Handle(args, context=self.context)
def testHandlerRaisesOnArbitraryFlowId(self): # Create a mock flow. self.flow_urn = flow.StartAFF4Flow( client_id=self.client_id, flow_name=discovery.Interrogate.__name__, token=self.token) args = vfs_plugin.ApiGetVfsFileContentUpdateStateArgs( operation_id=str(self.flow_urn)) # Our mock flow is not a MultiGetFile flow, so an error should be raised. with self.assertRaises(vfs_plugin.VfsFileContentUpdateNotFoundError): self.handler.Handle(args, token=self.token)
def testHandlerRaisesOnArbitraryFlowId(self): # Create a mock flow. if data_store.RelationalDBFlowsEnabled(): flow_id = flow.StartFlow( client_id=self.client_id.Basename(), flow_cls=discovery.Interrogate) else: flow_id = flow.StartAFF4Flow( client_id=self.client_id, flow_name=discovery.Interrogate.__name__, token=self.token).Basename() args = vfs_plugin.ApiGetVfsFileContentUpdateStateArgs( client_id=self.client_id, operation_id=flow_id) # Our mock flow is not a MultiGetFile flow, so an error should be raised. with self.assertRaises(vfs_plugin.VfsFileContentUpdateNotFoundError): self.handler.Handle(args, token=self.token)
def testHandlerReturnsCorrectStateForFlow(self): # Create a mock refresh operation. flow_id = self.CreateMultiGetFileFlow( self.client_id, file_path="fs/os/c/bin/bash") args = vfs_plugin.ApiGetVfsFileContentUpdateStateArgs( client_id=self.client_id, operation_id=flow_id) # Flow was started and should be running. result = self.handler.Handle(args, context=self.context) self.assertEqual(result.state, "RUNNING") # Terminate flow. flow_base.TerminateFlow(self.client_id, flow_id, "Fake error") # Recheck status and see if it changed. result = self.handler.Handle(args, context=self.context) self.assertEqual(result.state, "FINISHED")
def testHandlerReturnsCorrectStateForFlow(self): # Create a mock refresh operation. self.flow_urn = self.CreateMultiGetFileFlow( self.client_id, file_path="fs/os/c/bin/bash", token=self.token) args = vfs_plugin.ApiGetVfsFileContentUpdateStateArgs( operation_id=str(self.flow_urn)) # Flow was started and should be running. result = self.handler.Handle(args, token=self.token) self.assertEqual(result.state, "RUNNING") # Terminate flow. with aff4.FACTORY.Open( self.flow_urn, aff4_type=flow.GRRFlow, mode="rw", token=self.token) as flow_obj: flow_obj.GetRunner().Error("Fake error") # Recheck status and see if it changed. result = self.handler.Handle(args, token=self.token) self.assertEqual(result.state, "FINISHED")