예제 #1
0
        public void Login_context_test()
        {
            if (TestUtil.IgnoreCertificate)
            {
                System.Net.ServicePointManager.ServerCertificateValidationCallback = ((sender, certificate, chain, sslPolicyErrors) => true);
            }
            CloudCredentials credentials = new CloudCredentials();
            credentials.User = TestUtil.User;
            credentials.Password = TestUtil.Password;

            var client = TestUtil.GetClient();
            var authEndpoint = client.Info.GetInfo().Result.AuthorizationEndpoint;
            var authUri = new Uri(authEndpoint.TrimEnd('/') + "/oauth/token");


            UAAClient uaaClient = new UAAClient(authUri);

            var context = uaaClient.Login(credentials).Result;

            Assert.IsTrue(context.IsLoggedIn);
            Assert.AreEqual(context.Uri, authUri);
            Assert.IsNotNull(context.Token.AccessToken);
            Assert.IsNotNull(context.Token.RefreshToken);
            Assert.AreEqual(TestUtil.User, context.Token.UserName);
            Assert.IsNotNull(context.Token.UserGuid);
            Assert.IsFalse(context.Token.IsExpired);
            Assert.IsTrue(context.Token.Expires > DateTime.Now);

        }
예제 #2
0
        public static void ClassInit(TestContext context)
        {
            client = TestUtil.GetClient();
            CloudCredentials credentials = new CloudCredentials();
            credentials.User = TestUtil.User;
            credentials.Password = TestUtil.Password;
            try
            {
                client.Login(credentials).Wait();
            }
            catch (Exception ex)
            {
                Assert.Fail("Error while loging in" + ex.ToString());
            }
            CreateOrganizationRequest org = new CreateOrganizationRequest();
            org.Name = "test_" + Guid.NewGuid().ToString();
            var newOrg = client.Organizations.CreateOrganization(org).Result;
            orgGuid = newOrg.EntityMetadata.Guid;

            CreateSpaceRequest spc = new CreateSpaceRequest();
            spc.Name = "test_" + Guid.NewGuid().ToString();
            spc.OrganizationGuid = orgGuid;
            var newSpace = client.Spaces.CreateSpace(spc).Result;
            spaceGuid = newSpace.EntityMetadata.Guid;

            CreatesSharedDomainDeprecatedRequest r = new CreatesSharedDomainDeprecatedRequest();
            r.Name = Guid.NewGuid().ToString() + ".com";
            r.Wildcard = true;
            domainGuid = client.DomainsDeprecated.CreatesSharedDomainDeprecated(r).Result.EntityMetadata.Guid;
        }
예제 #3
0
        public static void ClassInit(TestContext context)
        {
            client = TestUtil.GetClient();
            CloudCredentials credentials = new CloudCredentials();
            credentials.User = TestUtil.User;
            credentials.Password = TestUtil.Password;
            try
            {
                client.Login(credentials).Wait();
            }
            catch (Exception ex)
            {
                Assert.Fail("Error while loging in" + ex.ToString());
            }

            CreateOrganizationRequest org = new CreateOrganizationRequest();
            org.Name = "test_" + Guid.NewGuid().ToString();
            var newOrg = client.Organizations.CreateOrganization(org).Result;
            orgGuid = newOrg.EntityMetadata.Guid;

            CreateSpaceRequest spc = new CreateSpaceRequest();
            spc.Name = "test_" + Guid.NewGuid().ToString();
            spc.OrganizationGuid = orgGuid;
            var newSpace = client.Spaces.CreateSpace(spc).Result;
            spaceGuid = newSpace.EntityMetadata.Guid;

            stackGuid = client.Stacks.ListAllStacks().Result[0].EntityMetadata.Guid;
        }
예제 #4
0
 public async Task<AuthenticationContext> Login(CloudCredentials credentials)
 {
     var token = await this.authentication.Authenticate(credentials);
     this.context.Token = token;
     this.context.Uri = this.targetUri;
     this.context.IsLoggedIn = true;
     return this.context;
 }
예제 #5
0
        public static void ClassInit(TestContext context)
        {
            Directory.CreateDirectory(tempAppPath);

            client = TestUtil.GetClient();
            CloudCredentials credentials = new CloudCredentials();
            credentials.User = TestUtil.User;
            credentials.Password = TestUtil.Password;
            try
            {
                client.Login(credentials).Wait();
            }
            catch (Exception ex)
            {
                Assert.Fail("Error while logging in" + ex.ToString());
            }

            PagedResponseCollection<ListAllSpacesResponse> spaces = client.Spaces.ListAllSpaces().Result;

            Guid spaceGuid = Guid.Empty;

            foreach (ListAllSpacesResponse space in spaces)
            {
                spaceGuid = space.EntityMetadata.Guid;
                break;
            }

            if (spaceGuid == Guid.Empty)
            {
                throw new Exception("No spaces found");
            }

            PagedResponseCollection<ListAllAppsResponse> apps = client.Apps.ListAllApps().Result;

            foreach (ListAllAppsResponse app in apps)
            {
                if (app.Name.StartsWith("logTest"))
                {
                    client.Apps.DeleteApp(app.EntityMetadata.Guid).Wait();
                    break;
                }
            }

            apprequest = new CreateAppRequest();
            apprequest.Name = "logTest" + Guid.NewGuid().ToString();
            apprequest.Memory = 512;
            apprequest.Instances = 1;
            apprequest.SpaceGuid = spaceGuid;
            apprequest.Buildpack = "https://github.com/ryandotsmith/null-buildpack.git";
            apprequest.EnvironmentJson = new Dictionary<string, string>() { { "env-test-1234", "env-test-value-1234" } };
            apprequest.Command = "export; cat content.txt; sleep 5000;";

            client.Apps.PushProgress += Apps_PushProgress;

            File.WriteAllText(Path.Combine(tempAppPath, "content.txt"), "dummy content");
        }
예제 #6
0
 public static void ClassInit(TestContext context)
 {
     client = TestUtil.GetClient();
     CloudCredentials credentials = new CloudCredentials();
     credentials.User = TestUtil.User;
     credentials.Password = TestUtil.Password;
     try
     {
         client.Login(credentials).Wait();
     }
     catch (Exception ex)
     {
         Assert.Fail("Error while loging in" + ex.ToString());
     }
 }
예제 #7
0
        public void Login_test()
        {
            var client = TestUtil.GetClient();
            CloudCredentials credentials = new CloudCredentials();
            credentials.User = TestUtil.User;
            credentials.Password = TestUtil.Password;
            try
            {
                client.Login(credentials).Wait();
            }
            catch (Exception ex)
            {
                Assert.Fail("Error while loging in" + ex.ToString());
            }

        }
예제 #8
0
        public void Login_refresh_token_test()
        {
            if (TestUtil.IgnoreCertificate)
            {
                System.Net.ServicePointManager.ServerCertificateValidationCallback = ((sender, certificate, chain, sslPolicyErrors) => true);
            }
            CloudCredentials credentials = new CloudCredentials();
            credentials.User = TestUtil.User;
            credentials.Password = TestUtil.Password;

            var client = TestUtil.GetClient();
            var authEndpoint = client.Info.GetInfo().Result.AuthorizationEndpoint;
            var authUri = new Uri(authEndpoint.TrimEnd('/') + "/oauth/token");


            UAAClient uaaClient = new UAAClient(authUri);

            var context = uaaClient.Login(credentials).Result;

            client.Login(context.Token.RefreshToken).Wait();

            client.Buildpacks.ListAllBuildpacks().Wait();
        }
예제 #9
0
 public void Login_incorrect_user_test()
 {
     var client = TestUtil.GetClient();
     CloudCredentials credentials = new CloudCredentials();
     credentials.User = Guid.NewGuid().ToString();
     credentials.Password = TestUtil.Password;
     try
     {
         client.Login(credentials).Wait();
     }
     catch (AggregateException aggEx)
     {
         Assert.IsInstanceOfType(aggEx.InnerException, typeof(AuthenticationException));
         Assert.IsTrue(aggEx.InnerException.Message.Contains("invalid_grant"));
     }
     catch (Exception ex)
     {
         Assert.Fail("Expected AuthError but got :" + ex.ToString());
     }
 }
예제 #10
0
        internal CloudFoundryClient InitClient()
        {
            CloudFoundryClient client = new CloudFoundryClient(new Uri(CFServerUri), new System.Threading.CancellationToken(), null, CFSkipSslValidation);

            if (string.IsNullOrWhiteSpace(CFUser)==false && (string.IsNullOrWhiteSpace(CFPassword) == false || CFSavedPassword))
            {
                if (string.IsNullOrWhiteSpace(CFPassword))
                {
                    this.CFPassword = CloudCredentialsManager.GetPassword(new Uri(this.CFServerUri), this.CFUser);

                    if (string.IsNullOrWhiteSpace(this.CFPassword))
                    {
                        throw new AuthenticationException(
                            string.Format(CultureInfo.InvariantCulture,
                            "Could not find a password for user '{0}' and target '{1}' in your local credentials store. Either make sure the entry exists in your credentials store, or provide CFPassword.",
                            this.CFUser,
                            this.CFServerUri));
                    }
                }

                CloudCredentials creds = new CloudCredentials();
                creds.User = CFUser;
                creds.Password = CFPassword;
                var authContext =  client.Login(creds).Result;
                if (this is LoginTask)
                {
                    if (authContext.Token != null)
                    {
                        ((LoginTask)this).CFRefreshToken = authContext.Token.RefreshToken;
                    }

                }
            }
            else if (string.IsNullOrWhiteSpace(CFRefreshToken) == false)
            {
                client.Login(CFRefreshToken).Wait();
            }
            else
            {
                throw new AuthenticationException("Could not authenticate client without refresh token or credentials.");
            }

            return client;
        }
예제 #11
0
        public static void ClassInit(TestContext context)
        {
            client = TestUtil.GetClient();
            CloudCredentials credentials = new CloudCredentials();
            credentials.User = TestUtil.User;
            credentials.Password = TestUtil.Password;
            try
            {
                client.Login(credentials).Wait();
            }
            catch (Exception ex)
            {
                Assert.Fail("Error while loging in" + ex.ToString());
            }

            PagedResponseCollection<ListAllSpacesResponse> spaces = client.Spaces.ListAllSpaces().Result;

            Guid spaceGuid = Guid.Empty;

            foreach (ListAllSpacesResponse space in spaces)
            {
                spaceGuid = space.EntityMetadata.Guid;
                break;
            }

            if (spaceGuid == Guid.Empty)
            {
                throw new Exception("No spaces found");
            }

            PagedResponseCollection<ListAllStacksResponse> stacks = client.Stacks.ListAllStacks().Result;

            var winStack = Guid.Empty;

            foreach (ListAllStacksResponse stack in stacks)
            {
                if (stack.Name == "win2012r2" || stack.Name == "win2012")
                {
                    winStack = stack.EntityMetadata.Guid;
                    break;
                }
            }

            if (winStack == Guid.Empty)
            {
                throw new Exception("Could not test on a deployment without a windows 2012 stack");
            }

            PagedResponseCollection<ListAllAppsResponse> apps = client.Apps.ListAllApps().Result;

            foreach (ListAllAppsResponse app in apps)
            {
                if (app.Name.StartsWith("simplePushTest"))
                {
                    client.Apps.DeleteApp(app.EntityMetadata.Guid).Wait();
                    break;
                }
            }

            apprequest = new CreateAppRequest();
            apprequest.Memory = 512;
            apprequest.Instances = 1;
            apprequest.SpaceGuid = spaceGuid;
            apprequest.StackGuid = winStack;

            client.Apps.PushProgress += Apps_PushProgress;
        }
 // { Token = new UAA.Authentication.Token() { RefreshToken = "mytoken" } } - Token is read-only and cannot be assigned to from shim context without fakeing uaa
 internal static Task<AuthenticationContext> CustomLogin(CloudController.V2.Client.CloudFoundryClient arg1, CloudCredentials arg2)
 {
     return Task.Factory.StartNew<AuthenticationContext>(() => { return new AuthenticationContext(); });
 }
예제 #13
0
        public async Task<AuthenticationContext> Login(CloudCredentials credentials)
        {
            var info = await this.Info.GetInfo();

            var authUrl = string.Format(CultureInfo.InvariantCulture, "{0}{1}", info.AuthorizationEndpoint.TrimEnd('/'), "/oauth/token");
            this.UAAClient = new UAAClient(new Uri(authUrl), this.HttpProxy, this.SkipCertificateValidation);

            var context = await this.UAAClient.Login(credentials);

            if (context.IsLoggedIn)
            {
                //// Workaround for HCF. Some CC requests (e.g. dev role + bind route, update app, etc..) will fail the first time after login with 401.
                //// Calling the CC's /v2/info endpoint will prevent this misbehavior.
                await this.Info.GetInfo();
            }

            return context;
        }