示例#1
0
        public void GetApiKey_ReturnsApiKeyForMatchingEndpointUrl_Success()
        {
            // Arrange
            string encryptedApiKey = EncryptionUtility.EncryptString(_apikey);

            var settings = new Mock <ISettings>(MockBehavior.Strict);

            settings.Setup(s => s.GetSection("apikeys"))
            .Returns(new MockSettingSection("apikeys",
                                            new AddItem(EndpointUrl, encryptedApiKey)
                                            ));

            //Act
            string apikey = CommandRunnerUtility.GetApiKey(settings.Object, EndpointUrl, NuGetConstants.V3FeedUrl);

            //Assert
            Assert.Equal(_apikey, apikey);
        }
示例#2
0
        public void GetApiKey_ReturnsDefaultGalleryServerUrlApiKeyIfSourceHostNameIsNuGetOrg_Success()
        {
            // Arrange
            string encryptedApiKey = EncryptionUtility.EncryptString(_apikey);

            var settings = new Mock <ISettings>(MockBehavior.Strict);

            settings.Setup(s => s.GetSection("apikeys"))
            .Returns(new MockSettingSection("apikeys",
                                            new AddItem("http://endpointUrl", _apikey),
                                            new AddItem(NuGetConstants.DefaultGalleryServerUrl, encryptedApiKey)
                                            ));

            //Act
            string apikey = CommandRunnerUtility.GetApiKey(settings.Object, EndpointUrl, NuGetConstants.V3FeedUrl);

            //Assert
            Assert.Equal(_apikey, apikey);
        }
示例#3
0
        public void GetApiKey_ReturnsApiKeyForMatchingPackageSourceUrl_Success()
        {
            // Arrange
            string encryptedApiKey = EncryptionUtility.EncryptString(_apikey);

            var settings = new Mock <ISettings>(MockBehavior.Strict);

            settings.Setup(s => s.GetSection("apikeys"))
            .Returns(new MockSettingSection("apikeys",
                                            new AddItem("http://endpointUrl", _apikey),//dummy endpoint url passed to ensure apikey is read from source url config entry
                                            new AddItem(NuGetConstants.V3FeedUrl, encryptedApiKey)
                                            ));

            //Act
            string apikey = CommandRunnerUtility.GetApiKey(settings.Object, EndpointUrl, NuGetConstants.V3FeedUrl);

            //Assert
            Assert.Equal(_apikey, apikey);
        }
示例#4
0
        public void GetApiKey_ReturnsNullWhenApiKeyIsNotFound_Success()
        {
            // Arrange
            string encryptedApiKey = EncryptionUtility.EncryptString(_apikey);

            var settings = new Mock <ISettings>(MockBehavior.Strict);

            settings.Setup(s => s.GetSection("apikeys"))
            .Returns(new MockSettingSection("apikeys",
                                            new AddItem("http://endpointUrl", encryptedApiKey),
                                            new AddItem(NuGetConstants.DefaultGalleryServerUrl, encryptedApiKey),
                                            new AddItem("https://sourceUrl", encryptedApiKey)
                                            ));

            //Act
            string apikey = CommandRunnerUtility.GetApiKey(settings.Object, EndpointUrl, "https://someothersourceUrl");

            //Assert
            Assert.True(string.IsNullOrEmpty(apikey));
        }