示例#1
0
        public void WorkflowResume_ServiceActionNullForResource_Fails()
        {
            //------------Setup for test--------------------------
            var resourceID = Guid.NewGuid();
            var values     = new Dictionary <string, StringBuilder>
            {
                { "resourceID", new StringBuilder(resourceID.ToString()) },
                { "environment", new StringBuilder("") },
                { "startActivityId", new StringBuilder("4032a11e-4fb3-4208-af48-b92a0602ab4b") },
                { "versionNumber", new StringBuilder("1") },
                { "currentuserprincipal", new StringBuilder(WindowsIdentity.GetCurrent().Name) }
            };
            var newDs = new DynamicService {
                Name = HandlesType()
            };
            var nullresourceCatalog = new Mock <IResourceCatalog>();

            nullresourceCatalog.Setup(catalog => catalog.GetService(GlobalConstants.ServerWorkspaceID, resourceID, "")).Returns(newDs);

            //------------Execute Test---------------------------

            var workflowResume = new WorkflowResume();

            workflowResume.ResourceCatalogInstance = nullresourceCatalog.Object;
            var jsonResult = workflowResume.Execute(values, null);

            //------------Assert Results-------------------------
            var serializer = new Dev2JsonSerializer();
            var result     = serializer.Deserialize <ExecuteMessage>(jsonResult);

            Assert.IsTrue(result.HasError);
            Assert.IsTrue(result.Message.ToString().Contains("Error resuming. ServiceAction is null for Resource ID"));
        }
示例#2
0
        public void WorkflowResume_Execute_WithEncryptedValues_Returns_Execution_Completed()
        {
            //------------Setup for test--------------------------
            var newexecutionEnvironment = CreateExecutionEnvironment();

            newexecutionEnvironment.Assign("[[UUID]]", "public", 0);
            newexecutionEnvironment.Assign("[[JourneyName]]", "whatever", 0);

            var resourceId       = Guid.NewGuid();
            var serializer       = new Dev2JsonSerializer();
            var identity         = new MockPrincipal(WindowsIdentity.GetCurrent().Name);
            var currentPrincipal = new GenericPrincipal(identity, new[] { "Role1", "Roll2" });

            Thread.CurrentPrincipal = currentPrincipal;
            var user   = DpapiWrapper.Encrypt(currentPrincipal.Identity.Name);
            var env    = DpapiWrapper.Encrypt(newexecutionEnvironment.ToJson());
            var values = new Dictionary <string, StringBuilder>
            {
                { "resourceID", new StringBuilder(resourceId.ToString()) },
                { "environment", new StringBuilder(env) },
                { "startActivityId", new StringBuilder("4032a11e-4fb3-4208-af48-b92a0602ab4b") },
                { "versionNumber", new StringBuilder("1") },
                { "currentuserprincipal", new StringBuilder(user) }
            };
            var resourceCatalog = new Mock <IResourceCatalog>();
            var newDs           = new DynamicService {
                Name = HandlesType(), ID = resourceId
            };
            var sa = new ServiceAction {
                Name = HandlesType(), ActionType = enActionType.InvokeManagementDynamicService, SourceMethod = HandlesType()
            };

            newDs.Actions.Add(sa);
            resourceCatalog.Setup(catalog => catalog.GetService(GlobalConstants.ServerWorkspaceID, It.IsAny <Guid>(), "")).Returns(newDs);

            var errors = new ErrorResultTO();
            var mockResumableExecutionContainer = new Mock <IResumableExecutionContainer>();

            mockResumableExecutionContainer.Setup(o => o.Execute(out errors, 0)).Verifiable();

            var mockResumableExecutionContainerFactory = new Mock <IResumableExecutionContainerFactory>();

            mockResumableExecutionContainerFactory.Setup(o => o.New(It.IsAny <Guid>(), It.IsAny <ServiceAction>(), It.IsAny <DsfDataObject>()))
            .Returns(mockResumableExecutionContainer.Object);
            CustomContainer.Register(mockResumableExecutionContainerFactory.Object);
            //------------Execute Test---------------------------

            var workflowResume = new WorkflowResume();

            workflowResume.ResourceCatalogInstance = resourceCatalog.Object;
            var jsonResult = workflowResume.Execute(values, null);

            //------------Assert Results-------------------------
            var result = serializer.Deserialize <ExecuteMessage>(jsonResult);

            Assert.IsFalse(result.HasError);
            Assert.AreEqual("Execution Completed.", result.Message.ToString());
        }
示例#3
0
        public void WorkflowResume_Execute_InvalidUserContext_Return_Authentication_Error_Fails()
        {
            //------------Setup for test--------------------------
            var resourceID           = Guid.NewGuid();
            var serializer           = new Dev2JsonSerializer();
            var currentuserprincipal = GlobalConstants.GenericPrincipal.Identity.Name;
            var values = new Dictionary <string, StringBuilder>
            {
                { "resourceID", new StringBuilder(resourceID.ToString()) },
                { "environment", new StringBuilder("") },
                { "startActivityId", new StringBuilder("4032a11e-4fb3-4208-af48-b92a0602ab4b") },
                { "versionNumber", new StringBuilder("1") },
                { "currentuserprincipal", new StringBuilder(currentuserprincipal) }
            };
            var authorizationService = new Mock <IAuthorizationService>();

            authorizationService.Setup(service => service.IsAuthorized(It.IsAny <AuthorizationContext>(), It.IsAny <Guid>())).Returns(false);

            var newDs = new DynamicService {
                Name = HandlesType(), ID = resourceID
            };
            var sa = new ServiceAction {
                Name = HandlesType(), ActionType = enActionType.InvokeManagementDynamicService, SourceMethod = HandlesType()
            };

            newDs.Actions.Add(sa);
            var resourceCatalog = new Mock <IResourceCatalog>();

            resourceCatalog.Setup(catalog => catalog.GetService(GlobalConstants.ServerWorkspaceID, It.IsAny <Guid>(), "")).Returns(newDs);


            var errors = new ErrorResultTO();
            var mockResumableExecutionContainer = new Mock <IResumableExecutionContainer>();

            mockResumableExecutionContainer.Setup(o => o.Execute(out errors, 0)).Verifiable();

            var mockResumableExecutionContainerFactory = new Mock <IResumableExecutionContainerFactory>();

            mockResumableExecutionContainerFactory.Setup(o => o.New(It.IsAny <Guid>(), It.IsAny <ServiceAction>(), It.IsAny <DsfDataObject>()))
            .Returns(mockResumableExecutionContainer.Object);
            CustomContainer.Register(mockResumableExecutionContainerFactory.Object);
            //------------Execute Test---------------------------

            var workflowResume = new WorkflowResume();

            workflowResume.ResourceCatalogInstance = resourceCatalog.Object;
            workflowResume.AuthorizationService    = authorizationService.Object;
            var jsonResult = workflowResume.Execute(values, null);

            //------------Assert Results-------------------------

            var result = serializer.Deserialize <ExecuteMessage>(jsonResult);

            Assert.IsTrue(result.HasError);
            Assert.IsTrue(result.Message.ToString().Contains("Authentication Error resuming"));
        }
示例#4
0
        public void WorkflowResume_Values_startActivityId_Missing_Fails()
        {
            //------------Setup for test--------------------------
            var values = new Dictionary <string, StringBuilder>
            {
                { "resourceID", new StringBuilder("ab04663e-1e09-4338-8f61-a06a7ae5ebab") },
                { "environment", new StringBuilder("NewEnvironment") },
                { "versionNumber", new StringBuilder("1") },
                { "currentuserprincipal", new StringBuilder("currentuserprincipal") }
            };
            var workflowResume = new WorkflowResume();
            //------------Execute Test---------------------------
            var jsonResult = workflowResume.Execute(values, null);
            //------------Assert Results-------------------------
            var serializer = new Dev2JsonSerializer();
            var result     = serializer.Deserialize <ExecuteMessage>(jsonResult);

            Assert.IsTrue(result.HasError);
            Assert.AreEqual("no startActivityId passed.", result.Message.ToString());
        }
示例#5
0
        public void WorkflowResume_Values_resourceID_Missing_Fails()
        {
            //------------Setup for test--------------------------
            var values = new Dictionary <string, StringBuilder>
            {
                { "environment", new StringBuilder("NewEnvironment") },
                { "startActivityId", new StringBuilder("4032a11e-4fb3-4208-af48-b92a0602ab4b") },
                { "versionNumber", new StringBuilder("1") },
                { "currentuserprincipal", new StringBuilder("username") }
            };
            var workflowResume = new WorkflowResume();
            //------------Execute Test---------------------------
            var jsonResult = workflowResume.Execute(values, null);
            //------------Assert Results-------------------------
            var serializer = new Dev2JsonSerializer();
            var result     = serializer.Deserialize <ExecuteMessage>(jsonResult);

            Assert.IsTrue(result.HasError);
            Assert.AreEqual("resourceID is missing", result.Message.ToString());
        }
示例#6
0
        public string ResumeJob(IDSFDataObject dsfDataObject, string jobId, bool overrideVariables, string environment)
        {
            try
            {
                var monitoringApi = _jobStorage.GetMonitoringApi();
                var jobDetails    = monitoringApi.JobDetails(jobId);
                var currentState  = jobDetails.History.OrderBy(s => s.CreatedAt).LastOrDefault();

                if (currentState?.StateName != "Scheduled" && currentState?.StateName != "Failed")
                {
                    return(GlobalConstants.Failed);
                }

                var values = jobDetails.Job.Args[0] as Dictionary <string, StringBuilder>;
                values.TryGetValue("environment", out StringBuilder persistedEnvironment);
                var decryptEnvironment = persistedEnvironment.ToString().CanBeDecrypted() ? DpapiWrapper.Decrypt(persistedEnvironment.ToString()) : persistedEnvironment.ToString();
                if (overrideVariables)
                {
                    if (values.ContainsKey("environment"))
                    {
                        values["environment"] = new StringBuilder(environment);
                    }
                }
                else
                {
                    values["environment"] = new StringBuilder(decryptEnvironment);
                }
                values.TryGetValue("currentuserprincipal", out StringBuilder currentUserPrincipal);
                var decryptCurrentUserPrincipal = currentUserPrincipal.ToString().CanBeDecrypted() ? DpapiWrapper.Decrypt(currentUserPrincipal.ToString()) : currentUserPrincipal.ToString();
                if (values.ContainsKey("environment"))
                {
                    values["currentuserprincipal"] = new StringBuilder(decryptCurrentUserPrincipal);
                }
                var workflowResume = new WorkflowResume();
                var result         = workflowResume.Execute(values, null);
                var serializer     = new Dev2JsonSerializer();
                var executeMessage = serializer.Deserialize <ExecuteMessage>(result);
                if (executeMessage.HasError)
                {
                    var failedState = new FailedState(new Exception(executeMessage.Message?.ToString()));
                    _client.ChangeState(jobId, failedState, ScheduledState.StateName);
                    return(GlobalConstants.Failed);
                }

                values.TryGetValue("resourceID", out StringBuilder workflowId);
                values.TryGetValue("environment", out StringBuilder environments);
                values.TryGetValue("startActivityId", out StringBuilder startActivityId);
                values.TryGetValue("versionNumber", out StringBuilder versionNumber);
                values.TryGetValue("currentprincipal", out StringBuilder currentprincipal);

                _stateNotifier = dsfDataObject.StateNotifier;
                var audit = new Audit
                {
                    WorkflowID     = workflowId?.ToString(),
                    Environment    = environments?.ToString(),
                    VersionNumber  = versionNumber?.ToString(),
                    NextActivityId = startActivityId?.ToString(),
                    AuditDate      = DateTime.Now,
                    AuditType      = "LogResumeExecutionState",
                    LogLevel       = LogLevel.Info,
                    User           = currentprincipal?.ToString()
                };

                _stateNotifier?.LogAdditionalDetail(audit, nameof(ResumeJob));
                var manuallyResumedState = new ManuallyResumedState(environments?.ToString());

                _client.ChangeState(jobId, manuallyResumedState, currentState?.StateName);
                return(GlobalConstants.Success);
            }
            catch (Exception ex)
            {
                _stateNotifier?.LogExecuteException(ex, this);
                Dev2Logger.Error(nameof(ResumeJob), ex, GlobalConstants.WarewolfError);
                throw new Exception(ex.Message);
            }
        }