예제 #1
0
        public void GivenIOpenSharepointSource(string p0)
        {
            var manageSharepointServerSource = ScenarioContext.Current.Get <SharepointServerSource>(Utils.ViewNameKey);
            var mockStudioUpdateManager      = new Mock <ISharePointSourceModel>();

            mockStudioUpdateManager.Setup(model => model.ServerName).Returns("localhost");
            var mockEventAggregator = new Mock <IEventAggregator>();
            var mockExecutor        = new Mock <IServer>();

            var username = @"dev2\IntegrationTester";
            var password = TestEnvironmentVariables.GetVar(username);
            var sharePointServiceSourceDefinition = new SharePointServiceSourceDefinition
            {
                Name               = "Test",
                Server             = $"http://{Depends.SharepointBackupServer}",
                AuthenticationType = AuthenticationType.Windows,
                UserName           = "******",
                Password           = password
            };

            mockStudioUpdateManager.Setup(model => model.FetchSource(It.IsAny <Guid>()))
            .Returns(sharePointServiceSourceDefinition);
            var manageSharepointServerSourceViewModel = new SharepointServerSourceViewModel(mockStudioUpdateManager.Object, mockEventAggregator.Object, sharePointServiceSourceDefinition, new SynchronousAsyncWorker(), mockExecutor.Object);

            manageSharepointServerSource.DataContext = manageSharepointServerSourceViewModel;
            ScenarioContext.Current.Remove("viewModel");
            ScenarioContext.Current.Add("viewModel", manageSharepointServerSourceViewModel);
        }
            public bool Impersonate(string username, string domain)
            {
                var token = IntPtr.Zero;

                var tokenDuplicate = IntPtr.Zero;
                var password       = TestEnvironmentVariables.GetVar(domain + "\\" + username);

                if (RevertToSelf() && LogonUser(username, domain, password, LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, out token) && DuplicateToken(token, 2, out tokenDuplicate) != 0)
                {
                    var tempWindowsIdentity = new WindowsIdentity(tokenDuplicate);
                    _impersonationContext = tempWindowsIdentity.Impersonate();
                    if (_impersonationContext != null)
                    {
                        ClaimsPrincipal principal = new WindowsPrincipal(tempWindowsIdentity);
                        Thread.CurrentPrincipal = principal;
                        CloseHandle(token);
                        CloseHandle(tokenDuplicate);
                        return(true);
                    }
                }
                if (token != IntPtr.Zero)
                {
                    CloseHandle(token);
                }
                if (tokenDuplicate != IntPtr.Zero)
                {
                    CloseHandle(tokenDuplicate);
                }
                return(false);
            }
예제 #3
0
        public void GivenIOpenWebSource(string resourceName)
        {
            var manageWebserviceSourceControl = scenarioContext.Get <ManageWebserviceSourceControl>(Utils.ViewNameKey);
            var mockStudioUpdateManager       = new Mock <IManageWebServiceSourceModel>();

            mockStudioUpdateManager.Setup(model => model.ServerName).Returns("localhost");
            var mockEventAggregator = new Mock <IEventAggregator>();
            var mockExecutor        = new Mock <IExternalProcessExecutor>();

            var username = @"dev2\IntegrationTester";
            var password = TestEnvironmentVariables.GetVar(username);
            var webServiceSourceDefinition = new WebServiceSourceDefinition
            {
                Name         = "Test",
                HostName     = "http://RSAKLFSVRTFSBLD/IntegrationTestSite",
                DefaultQuery = "/GetCountries.ashx?extension=json&prefix=a",
                UserName     = "******",
                Password     = password
            };

            mockStudioUpdateManager.Setup(model => model.FetchSource(It.IsAny <Guid>()))
            .Returns(webServiceSourceDefinition);
            var manageWebserviceSourceViewModel = new ManageWebserviceSourceViewModel(mockStudioUpdateManager.Object, mockEventAggregator.Object, webServiceSourceDefinition, new SynchronousAsyncWorker(), mockExecutor.Object);

            manageWebserviceSourceControl.DataContext = manageWebserviceSourceViewModel;
            scenarioContext.Remove("viewModel");
            scenarioContext.Add("viewModel", manageWebserviceSourceViewModel);
        }
예제 #4
0
        public void LogonProvider_DoLogon_ErrorThrowsMessage()
        {
            var mockLoginImpl = new Mock <ILoginApi>();

            var provider = new LogonProvider(mockLoginImpl.Object);

            var username = @"dev2\IntegrationTester";
            var password = TestEnvironmentVariables.GetVar(username);

            var v = It.IsAny <SafeTokenHandle>();

            mockLoginImpl.Setup(o => o.LogonUser("IntegrationTester", "DEV2", password, 3, 3, out v))
            .Throws(new Exception("some exception"));


            var ioPath          = new Dev2ActivityIOPath(Interfaces.Enums.enActivityIOPathType.FileSystem, @"C:\", @"DEV2\IntegrationTester", password, false, null);
            var expectedMessage = string.Format(ErrorResource.FailedToAuthenticateUser, "IntegrationTester", ioPath.Path);

            var hadException = false;

            try
            {
                provider.DoLogon(ioPath);
            }
            catch (Exception e)
            {
                hadException = true;
                Assert.AreEqual(expectedMessage, e.Message);
            }
            Assert.IsTrue(hadException, "expected exception");

            mockLoginImpl.Verify(o => o.LogonUser("IntegrationTester", "DEV2", password, 3, 3, out v), Times.Once);
        }
예제 #5
0
        public void GivenUserAs(string username)
        {
            var password     = TestEnvironmentVariables.GetVar(username);
            var serverSource = ScenarioContext.Current.Get <IServerSource>("serverSource");

            serverSource.UserName = username;
            serverSource.Password = password;
            ScenarioContext.Current.Set(serverSource, "serverSource");
        }
예제 #6
0
        public void WhenPasswordField()
        {
            var manageWebserviceSourceControl = scenarioContext.Get <ManageWebserviceSourceControl>(Utils.ViewNameKey);
            var viewModel = scenarioContext.Get <ManageWebserviceSourceViewModel>("viewModel");
            var username  = @"dev2\IntegrationTester";
            var password  = TestEnvironmentVariables.GetVar(username);

            Assert.AreEqual(password, viewModel.Password);
            Assert.AreEqual(password, manageWebserviceSourceControl.GetPassword());
        }
예제 #7
0
        public void GivenITypePassword()
        {
            var username = @"dev2\IntegrationTester";
            var password = TestEnvironmentVariables.GetVar(username);
            var manageSharepointServerSource = ScenarioContext.Current.Get <SharepointServerSource>(Utils.ViewNameKey);

            manageSharepointServerSource.EnterPassword(password);
            var viewModel = ScenarioContext.Current.Get <SharepointServerSourceViewModel>("viewModel");

            Assert.AreEqual(password, viewModel.Password);
        }
예제 #8
0
        public void FileSystemQuery_ShareCollection()
        {
            var shareCollection = new ShareCollection(@"\\rsaklfsvrpdc.dev2.local\");

            if (shareCollection.Count <= 0)
            {
                var username = @"dev2\IntegrationTester";
                var password = TestEnvironmentVariables.GetVar(username);
                //------------Execute Test---------------------------
                AuthenticateForSharedFolder(@"\\rsaklfsvrpdc.dev2.local\apps", username, password);
                Thread.Sleep(1000);
                shareCollection = new ShareCollection(@"\\rsaklfsvrpdc.dev2.local\");
            }
            //------------Assert Results-------------------------
            Assert.IsTrue(shareCollection.Count > 0, "Cannot get shared directory information.");
        }
예제 #9
0
        public void LogonProvider_DoLogon_LogonNetwork()
        {
            bool loginReturnStatus = true;

            var mockLoginImpl = new Mock <ILoginApi>();

            var provider = new LogonProvider(mockLoginImpl.Object);

            var username = @"dev2\IntegrationTester";
            var password = TestEnvironmentVariables.GetVar(username);

            var v = It.IsAny <SafeTokenHandle>();

            mockLoginImpl.Setup(o => o.LogonUser("IntegrationTester", "dev2", password, 3, 3, out v))
            .Returns(loginReturnStatus);


            var ioPath = new Dev2ActivityIOPath(Interfaces.Enums.enActivityIOPathType.FileSystem, @"C:\", username, password, false, null);

            provider.DoLogon(ioPath);

            mockLoginImpl.Verify(o => o.LogonUser("IntegrationTester", "dev2", password, 3, 3, out v), Times.Once);
        }
예제 #10
0
 public void GivenUserAs(string username) => AddUserToServerSource(username, TestEnvironmentVariables.GetVar(username));
예제 #11
0
        public void GivenIOpenServerSource(string editingServerSource)
        {
            var manageServerControl     = ScenarioContext.Current.Get <ManageServerControl>(Core.Utils.ViewNameKey);
            var mockStudioUpdateManager = new Mock <IManageServerSourceModel>();

            mockStudioUpdateManager.Setup(model => model.ServerName).Returns("localhost");
            mockStudioUpdateManager.Setup(model => model.GetComputerNames()).Returns(new List <string> {
                "rsaklfhuggspc", "barney", "SANDBOX-1"
            });
            var mockEventAggregator = new Mock <IEventAggregator>();
            var mockExecutor        = new Mock <IExternalProcessExecutor>();

            var username = @"dev2\IntegrationTester";
            var password = TestEnvironmentVariables.GetVar(username);

            var serverSourceDefinition = new Dev2.Common.ServerSource
            {
                Name               = "ServerSource",
                Address            = "https://SANDBOX-1:3143",
                ServerName         = "SANDBOX-1",
                AuthenticationType = AuthenticationType.User,
                UserName           = "******",
                Password           = password
            };
            var externalServerSourceDefinition = new Dev2.Common.ServerSource
            {
                Name               = "TestWarewolf",
                Address            = "http://test-warewolf.cloudapp.net:3142",
                ServerName         = "test-warewolf.cloudapp.net",
                AuthenticationType = AuthenticationType.Public
            };

            Dev2.Common.ServerSource serverSource;

            switch (editingServerSource)
            {
            case "ServerSource":
                serverSource = serverSourceDefinition;
                break;

            case "TestWarewolf":
                serverSource = externalServerSourceDefinition;
                break;

            default:
                serverSource = serverSourceDefinition;
                break;
            }


            mockStudioUpdateManager.Setup(model => model.FetchSource(It.IsAny <Guid>()))
            .Returns(serverSource);
            FeatureContext.Current["svrsrc"] = serverSource;
            var viewModel = GetViewModel(manageServerControl);
            var manageServerSourceViewModel = new ManageNewServerViewModel(mockStudioUpdateManager.Object, mockEventAggregator.Object, serverSource, new SynchronousAsyncWorker(), mockExecutor.Object);

            manageServerControl.EnterPassword(manageServerSourceViewModel.Password);
            manageServerControl.EnterUserName(manageServerSourceViewModel.UserName);
            manageServerControl.SetPort(manageServerSourceViewModel.SelectedPort);
            manageServerControl.SetProtocol(manageServerSourceViewModel.Protocol);
            manageServerControl.SetAuthenticationType(manageServerSourceViewModel.AuthenticationType);
            manageServerControl.EnterServerName(manageServerSourceViewModel.ServerName.Name);
            manageServerControl.SelectServer(manageServerSourceViewModel.ServerName.Name);
            viewModel.Password           = manageServerSourceViewModel.Password;
            viewModel.UserName           = manageServerSourceViewModel.UserName;
            viewModel.Protocol           = manageServerSourceViewModel.Protocol;
            viewModel.AuthenticationType = manageServerSourceViewModel.AuthenticationType;
            viewModel.ServerName         = manageServerSourceViewModel.ServerName;
            viewModel.Header             = manageServerSourceViewModel.Header;
            viewModel.HeaderText         = manageServerSourceViewModel.HeaderText;
            viewModel.Item = manageServerSourceViewModel.Item;
        }
예제 #12
0
 public bool Impersonate(string username, string domain) => Impersonate(username, domain, TestEnvironmentVariables.GetVar(domain + "\\" + username));
예제 #13
0
 public void GivenIAuthenticateForShareAtAsUserWithPassword(string p0, string p1) => FileSystemQueryTest.AuthenticateForSharedFolder(p0, p1, TestEnvironmentVariables.GetVar(p1));
예제 #14
0
 public void GivenHasAUsernameOfAndAPasswordOf(string scheduleName, string userName)
 {
     _scenarioContext.Add("UserName", userName);
     _scenarioContext.Add("Password", TestEnvironmentVariables.GetVar(userName));
 }
예제 #15
0
        public void AuthorizationServiceBase_IsAuthorizedToConnect_ToLocalServer_AdministratorsMembersOfWarewolfGroup_WhenMemberOfAdministrator_ExpectTrue()
        {
            //------------Setup for test--------------------------
            var getPassword = TestEnvironmentVariables.GetVar("dev2\\IntegrationTester");
            // permissions setup
            var warewolfGroupOps = MoqInstallerActionFactory.CreateSecurityOperationsObject();

            //Delete warewolf if already a member...
            warewolfGroupOps.DeleteWarewolfGroup();
            warewolfGroupOps.AddWarewolfGroup();

            var result = warewolfGroupOps.IsAdminMemberOfWarewolf();

            Assert.IsFalse(result);

            // Setup rest of test
            var resource           = Guid.NewGuid();
            var securityPermission = new WindowsGroupPermission {
                IsServer = false, ResourceID = resource, Permissions = Permissions.View, WindowsGroup = GlobalConstants.WarewolfGroup
            };
            var securityService = new Mock <ISecurityService>();
            var user            = new Mock <IPrincipal>();
            var actualGChildren = new List <Mock <IDirectoryEntry> > {
                new Mock <IDirectoryEntry>()
            };
            var gChildren      = new Mock <IDirectoryEntries>();
            var actualChildren = new List <Mock <IDirectoryEntry> > {
                new Mock <IDirectoryEntry>()
            };
            var children = new Mock <IDirectoryEntries>();
            var dir      = new Mock <IDirectoryEntryFactory>();

            securityService.SetupGet(p => p.Permissions).Returns(new List <WindowsGroupPermission> {
                securityPermission
            });
            user.Setup(u => u.Identity.Name).Returns("TestUser");
            actualGChildren.ForEach(b => b.Setup(a => a.Name).Returns("Warewolf Administrators"));
            actualGChildren.ForEach(b => b.Setup(a => a.SchemaClassName).Returns("Computer"));

            gChildren.Setup(a => a.GetEnumerator()).Returns(actualGChildren.Select(a => a.Object).GetEnumerator());
            actualChildren.First().Setup(a => a.Children).Returns(gChildren.Object);
            children.Setup(a => a.GetEnumerator()).Returns(actualChildren.Select(a => a.Object).GetEnumerator());
            SchemaNameCollection filterList = new DirectoryEntry("LDAP://dev2.local", "IntegrationTester", getPassword).Children.SchemaFilter;

            children.Setup(a => a.SchemaFilter).Returns(filterList);
            var ss = "WinNT://" + Environment.MachineName + ",computer";

            dir.Setup(a => a.Create(ss)).Returns(new TestDirectoryEntry(ss));

            var authorizationService = new TestAuthorizationServiceBase(dir.Object, securityService.Object, true, true, false)
            {
                User = user.Object
            };

            authorizationService.MemberOfAdminOverride = true;
            //------------Execute Test---------------------------
            var isMember = authorizationService.AreAdministratorsMembersOfWarewolfAdministrators();

            //------------Assert Results-------------------------
            Assert.IsTrue(isMember);
        }