Beispiel #1
0
        public ApiKeyAuthTests()
        {
            //System.Diagnostics.Debugger.Break();
            appHost = new AppHost()
                      .Init()
                      .Start("http://*:2337/");

            var client   = new JsonServiceClient(ListeningOn);
            var response = client.Post(new Register
            {
                UserName    = Username,
                Password    = Password,
                Email       = "as@if{0}.com",
                DisplayName = "DisplayName",
                FirstName   = "FirstName",
                LastName    = "LastName",
            });

            userId  = response.UserId;
            apiRepo = (IManageApiKeys)appHost.Resolve <IAuthRepository>();
            var apiKeys = apiRepo.GetUserApiKeys(userId);

            liveKey = apiKeys.First(x => x.Environment == "live");
            testKey = apiKeys.First(x => x.Environment == "test");
        }
        public void Does_create_multiple_ApiKeys()
        {
            var apiKeys = apiRepo.GetUserApiKeys(userId);

            Assert.That(apiKeys.Count, Is.EqualTo(
                            apiProvider.Environments.Length * apiProvider.KeyTypes.Length));

            Assert.That(apiKeys.All(x => x.UserAuthId != null));
            Assert.That(apiKeys.All(x => x.Environment != null));
            Assert.That(apiKeys.All(x => x.KeyType != null));
            Assert.That(apiKeys.All(x => x.CreatedDate != default(DateTime)));
            Assert.That(apiKeys.All(x => x.CancelledDate == null));
            Assert.That(apiKeys.All(x => x.ExpiryDate == null));

            foreach (var apiKey in apiKeys)
            {
                var byId = apiRepo.GetApiKey(apiKey.Id);
                Assert.That(byId.Id, Is.EqualTo(apiKey.Id));
            }
        }
        public StatelessAuthTests()
        {
            //LogManager.LogFactory = new ConsoleLogFactory();
            appHost = CreateAppHost()
                      .Init()
                      .Start("http://*:2337/");

            var client   = GetClient();
            var response = client.Post(new Register
            {
                UserName    = "******",
                Password    = "******",
                Email       = "as@if{0}.com",
                DisplayName = "DisplayName",
                FirstName   = "FirstName",
                LastName    = "LastName",
            });

            userId  = response.UserId;
            apiRepo = (IManageApiKeys)appHost.Resolve <IAuthRepository>();
            ApiKey  = apiRepo.GetUserApiKeys(userId).First(x => x.Environment == "test");

            apiProvider = (ApiKeyAuthProvider)AuthenticateService.GetAuthProvider(ApiKeyAuthProvider.Name);
        }