Beispiel #1
0
        public DefaultServiceResolver(string packagePath, NameValueCollection settings)
        {
            _hashProvider = new CryptoHashProvider(Core.Constants.HashAlgorithm);

            _settingsProvider = new WebConfigSettingsProvider(settings);

            _packageRepository = new ServerPackageRepository(packagePath, _hashProvider, _settingsProvider, new TraceLogger());

            _packageAuthenticationService = new PackageAuthenticationService(settings);
        }
Beispiel #2
0
        public void AuthenticationServiceReturnsFalseIfRequireApiKeyValueIsMalformed(string requireApiKey)
        {
            // Arrange
            var collection = new NameValueCollection();

            collection.Add("requireApiKey", requireApiKey);

            // Act
            bool result = PackageAuthenticationService.IsAuthenticatedInternal("test-apikey", collection);

            // Assert
            Assert.False(result);
        }
Beispiel #3
0
        public void AuthenticationServiceReturnsTrueIfKeyMatchesConfigurationKey(string key)
        {
            // Arrange
            var collection = new NameValueCollection();

            collection.Add("requireApiKey", "true");
            collection.Add("apiKey", "test-key");

            // Act
            bool result = PackageAuthenticationService.IsAuthenticatedInternal(key, collection);

            // Assert
            Assert.True(result);
        }
Beispiel #4
0
        public void AuthenticationServiceReturnsFalseIfKeyDoesNotMatchConfigurationKey()
        {
            // Arrange
            var collection = new NameValueCollection();

            collection.Add("requireApiKey", "true");
            collection.Add("apiKey", "test-key");

            // Act
            bool result = PackageAuthenticationService.IsAuthenticatedInternal("incorrect-key", collection);

            // Assert
            Assert.False(result);
        }
Beispiel #5
0
        public void AuthenticationServiceReturnsTrueIfRequireApiKeyValueIsSetToFalse(string keyValue)
        {
            // Arrange
            var collection = new NameValueCollection();

            collection.Add("requireApiKey", keyValue);
            collection.Add("apiKey", "test-key");

            // Act
            bool result = PackageAuthenticationService.IsAuthenticatedInternal("incorrect-key", collection);

            // Assert
            Assert.True(result);
        }
Beispiel #6
0
        public void AuthenticationServiceReturnsFalseIfRequireApiKeyValueIsMalformed(string requireApiKey)
        {
            // Arrange
            var collection = new NameValueCollection
            {
                { "requireApiKey", requireApiKey }
            };
            var target = new PackageAuthenticationService(collection);

            // Act
            var result = target.IsAuthenticated(user: null, apiKey: "test-apikey", packageId: null);

            // Assert
            Assert.False(result);
        }
Beispiel #7
0
        public void AuthenticationServiceReturnsFalseIfKeyDoesNotMatchConfigurationKey(string key)
        {
            // Arrange
            var collection = new NameValueCollection
            {
                { "requireApiKey", "true" },
                { "apiKey", "test-key" }
            };

            // Act
            var result = PackageAuthenticationService.IsAuthenticatedInternal(key, collection);

            // Assert
            Assert.False(result);
        }
Beispiel #8
0
        public void AuthenticationServiceReturnsTrueIfKeyMatchesConfigurationKey(string key)
        {
            // Arrange
            var collection = new NameValueCollection
            {
                { "requireApiKey", "true" },
                { "apiKey", "test-key" }
            };
            var target = new PackageAuthenticationService(collection);

            // Act
            var result = target.IsAuthenticated(user: null, apiKey: key, packageId: null);

            // Assert
            Assert.True(result);
        }
Beispiel #9
0
        public void AuthenticationServiceReturnsTrueIfRequireApiKeyValueIsSetToFalse(string keyValue)
        {
            // Arrange
            var collection = new NameValueCollection
            {
                { "requireApiKey", keyValue },
                { "apiKey", "test-key" }
            };
            var target = new PackageAuthenticationService(collection);

            // Act
            var result = target.IsAuthenticated(user: null, apiKey: "incorrect-key", packageId: null);

            // Assert
            Assert.True(result);
        }