def testWorksCorrectlyWithTestOutputPluginOnFlowWithSingleResult(self): with test_lib.FakeTime(42): flow_urn = flow.StartAFF4Flow( flow_name=flow_test_lib.DummyFlowWithSingleReply.__name__, client_id=self.client_id, token=self.token) flow_test_lib.TestFlowHelper(flow_urn, token=self.token) result = self.handler.Handle( flow_plugin.ApiGetExportedFlowResultsArgs( client_id=self.client_id, flow_id=flow_urn.Basename(), plugin_name=test_plugins.TestInstantOutputPlugin.plugin_name), token=self.token) chunks = list(result.GenerateContent()) self.assertListEqual( chunks, ["Start: %s" % utils.SmartStr(flow_urn), "Values of type: RDFString", "First pass: oh (source=%s)" % utils.SmartStr(self.client_id), "Second pass: oh (source=%s)" % utils.SmartStr(self.client_id), "Finish: %s" % utils.SmartStr(flow_urn)]) # pyformat: disable
def testAllClientFlowsMethodsAreAccessChecked(self): args = api_flow.ApiListFlowsArgs(client_id=self.client_id) self.CheckMethodIsAccessChecked( self.router.ListFlows, "CheckClientAccess", args=args) args = api_flow.ApiGetFlowArgs(client_id=self.client_id) self.CheckMethodIsAccessChecked( self.router.GetFlow, "CheckClientAccess", args=args) args = api_flow.ApiCreateFlowArgs(client_id=self.client_id) self.CheckMethodIsAccessChecked( self.router.CreateFlow, "CheckClientAccess", args=args) self.CheckMethodIsAccessChecked( self.router.CreateFlow, "CheckIfCanStartClientFlow", args=args) args = api_flow.ApiCancelFlowArgs(client_id=self.client_id) self.CheckMethodIsAccessChecked( self.router.CancelFlow, "CheckClientAccess", args=args) args = api_flow.ApiListFlowRequestsArgs(client_id=self.client_id) self.CheckMethodIsAccessChecked( self.router.ListFlowRequests, "CheckClientAccess", args=args) args = api_flow.ApiListFlowResultsArgs(client_id=self.client_id) self.CheckMethodIsAccessChecked( self.router.ListFlowResults, "CheckClientAccess", args=args) args = api_flow.ApiGetExportedFlowResultsArgs(client_id=self.client_id) self.CheckMethodIsAccessChecked( self.router.GetExportedFlowResults, "CheckClientAccess", args=args) args = api_flow.ApiGetFlowResultsExportCommandArgs(client_id=self.client_id) self.CheckMethodIsAccessChecked( self.router.GetFlowResultsExportCommand, "CheckClientAccess", args=args) args = api_flow.ApiGetFlowFilesArchiveArgs(client_id=self.client_id) self.CheckMethodIsAccessChecked( self.router.GetFlowFilesArchive, "CheckClientAccess", args=args) args = api_flow.ApiListFlowOutputPluginsArgs(client_id=self.client_id) self.CheckMethodIsAccessChecked( self.router.ListFlowOutputPlugins, "CheckClientAccess", args=args) args = api_flow.ApiListFlowOutputPluginLogsArgs(client_id=self.client_id) self.CheckMethodIsAccessChecked( self.router.ListFlowOutputPluginLogs, "CheckClientAccess", args=args) args = api_flow.ApiListFlowOutputPluginErrorsArgs(client_id=self.client_id) self.CheckMethodIsAccessChecked( self.router.ListFlowOutputPluginErrors, "CheckClientAccess", args=args) args = api_flow.ApiListFlowLogsArgs(client_id=self.client_id) self.CheckMethodIsAccessChecked( self.router.ListFlowLogs, "CheckClientAccess", args=args)
def MockMethodIsCalled(): try: # Mock should be called twice: once for HEAD (to check permissions) # and once for GET methods. mock_method.assert_called_with( api_flow.ApiGetExportedFlowResultsArgs( client_id=self.client_id, flow_id=flow_urn.Basename(), plugin_name=plugin), token=mock.ANY) return True except AssertionError: return False
def testWorksCorrectlyWithTestOutputPluginOnFlowWithSingleResult(self): with test_lib.FakeTime(42): sid = flow_test_lib.TestFlowHelper(compatibility.GetName( flow_test_lib.DummyFlowWithSingleReply), client_id=self.client_id, token=self.token) result = self.handler.Handle(flow_plugin.ApiGetExportedFlowResultsArgs( client_id=self.client_id, flow_id=sid, plugin_name=test_plugins.TestInstantOutputPlugin.plugin_name), token=self.token) chunks = list(result.GenerateContent()) self.assertListEqual(chunks, [ "Start: aff4:/%s/flows/%s" % (self.client_id, sid), "Values of type: RDFString", "First pass: oh (source=aff4:/%s)" % self.client_id, "Second pass: oh (source=aff4:/%s)" % self.client_id, "Finish: aff4:/%s/flows/%s" % (self.client_id, sid) ])