Exemplo n.º 1
0
        public void TestAuthenticate()
        {
            IIdentityProvider provider   = Bootstrapper.CreateIdentityProvider();
            UserAccess        userAccess = provider.Authenticate();

            Assert.IsNotNull(userAccess);
            Assert.IsNotNull(userAccess.Token);
            Assert.IsNotNull(userAccess.Token.Id);
            Assert.IsNotNull(userAccess.Token.Expires);
            Assert.IsFalse(userAccess.Token.IsExpired);

            Assert.IsNotNull(userAccess.User);
            Assert.IsNotNull(userAccess.User.Id);
            Assert.IsNotNull(userAccess.User.Name);

            Assert.IsNotNull(userAccess.ServiceCatalog);

            Console.Error.WriteLine(JsonConvert.SerializeObject(userAccess, Formatting.Indented));

            Console.WriteLine("Available Services:");
            foreach (ServiceCatalog serviceCatalog in userAccess.ServiceCatalog)
            {
                Console.WriteLine("    {0} ({1})", serviceCatalog.Name, serviceCatalog.Type);
                var regions = serviceCatalog.Endpoints.Select(i => i.Region ?? "global").OrderBy(i => i, StringComparer.OrdinalIgnoreCase);
                Console.WriteLine("        {0}", string.Join(", ", regions));
            }
        }
Exemplo n.º 2
0
        public void TestValidateToken()
        {
            IIdentityProvider provider   = Bootstrapper.CreateIdentityProvider();
            UserAccess        userAccess = provider.Authenticate();

            Assert.IsNotNull(userAccess);
            Assert.IsNotNull(userAccess.Token);
            Assert.IsNotNull(userAccess.Token.Id);

            try
            {
                UserAccess validated = provider.ValidateToken(userAccess.Token.Id);
                Assert.IsNotNull(validated);
                Assert.IsNotNull(validated.Token);
                Assert.AreEqual(userAccess.Token.Id, validated.Token.Id);

                Assert.IsNotNull(validated.User);
                Assert.AreEqual(userAccess.User.Id, validated.User.Id);
                Assert.AreEqual(userAccess.User.Name, validated.User.Name);
                Assert.AreEqual(userAccess.User.DefaultRegion, validated.User.DefaultRegion);
            }
            catch (UserNotAuthorizedException ex)
            {
                if (ex.Response.StatusCode != HttpStatusCode.Forbidden)
                {
                    throw;
                }

                Assert.Inconclusive("The service does not allow this user to access the Validate Token API.");
            }
        }
Exemplo n.º 3
0
        public void TestListEndpoints()
        {
            IIdentityProvider provider   = Bootstrapper.CreateIdentityProvider();
            UserAccess        userAccess = provider.Authenticate();

            Assert.IsNotNull(userAccess);
            Assert.IsNotNull(userAccess.Token);
            Assert.IsNotNull(userAccess.Token.Id);

            try
            {
                IEnumerable <ExtendedEndpoint> endpoints = provider.ListEndpoints(userAccess.Token.Id);
                Console.WriteLine(JsonConvert.SerializeObject(userAccess, Formatting.Indented));
            }
            catch (UserNotAuthorizedException ex)
            {
                if (ex.Response.StatusCode != HttpStatusCode.Forbidden)
                {
                    throw;
                }

                Assert.Inconclusive("The service does not allow this user to access the List Endpoints API.");
            }
        }