private static ClientAuthorizationSettings GetAuthSettingsVersion2(ILeverConfiguration configuration, string client)
        {
            var clientConfiguration = ClientConfigurationHelper.GetConfigurationForClient(configuration, client);

            if (clientConfiguration == null)
            {
                return(null);
            }
            if (string.IsNullOrWhiteSpace(clientConfiguration.Authentication))
            {
                return(new ClientAuthorizationSettings
                {
                    AuthorizationType = ClientAuthorizationSettings.AuthorizationTypeEnum.None
                });
            }

            var authentications = GetAuthentications(configuration);

            if (authentications == null || !authentications.TryGetValue(clientConfiguration.Authentication, out var authentication))
            {
                throw new FulcrumResourceException($"Client '{client}' refers to authentication '{clientConfiguration.Authentication}', which does not exist");
            }

            return(authentication);
        }
Example #2
0
        public void MultipleAuthenticationsFail()
        {
            SetupConfigMock(new Dictionary <string, string>
            {
                { "Authorization", "bar" }
            });

            ClientConfigurationHelper.GetConfigurationForClient(LeverConfiguration, ClientName);
        }
Example #3
0
        public void NoAuthentication()
        {
            SetupConfigMock(null);

            var config = ClientConfigurationHelper.GetConfigurationForClient(LeverConfiguration, ClientNameNoAuth);

            Assert.IsNotNull(config);
            Assert.IsNull(config.Authentication);
        }
Example #4
0
        public void NullHeaders()
        {
            SetupConfigMock(null);

            var config = ClientConfigurationHelper.GetConfigurationForClient(LeverConfiguration, ClientName);

            Assert.IsNotNull(config);
            Assert.IsNull(config.RequestHeaders);
        }
Example #5
0
        public void EmptyHeaders()
        {
            SetupConfigMock(new Dictionary <string, string>());

            var config = ClientConfigurationHelper.GetConfigurationForClient(LeverConfiguration, ClientName);

            Assert.IsNotNull(config?.RequestHeaders);
            Assert.AreEqual(0, config.RequestHeaders.Count);
        }
Example #6
0
        public void SingleHeader()
        {
            SetupConfigMock(new Dictionary <string, string>
            {
                { "foo", "bar" }
            });

            var config = ClientConfigurationHelper.GetConfigurationForClient(LeverConfiguration, ClientName);

            Assert.IsNotNull(config?.RequestHeaders);
            Assert.AreEqual(1, config.RequestHeaders.Count);
            Assert.IsTrue(config.RequestHeaders.ContainsKey("foo"));
            Assert.AreEqual("bar", config.RequestHeaders["foo"]);
            Assert.AreEqual("auth", config.Authentication);
        }
Example #7
0
        public void ConfigurationFromJsonFile()
        {
            // https://docs.nexus.link/docs/client-authentication-methods
            LeverConfiguration = new MockLeverConfiguration(JObject.Parse(File.ReadAllText($"{AppDomain.CurrentDomain.BaseDirectory}\\Clients\\client-config.json")));

            var config = ClientConfigurationHelper.GetConfigurationForClient(LeverConfiguration, "client-a");

            Assert.IsNotNull(config?.RequestHeaders);
            Assert.AreEqual(2, config.RequestHeaders.Count);
            Assert.IsTrue(config.RequestHeaders.ContainsKey("header-a"));
            Assert.IsTrue(config.RequestHeaders.ContainsValue("value-a"));
            Assert.IsTrue(config.RequestHeaders.ContainsKey("header-b"));
            Assert.IsTrue(config.RequestHeaders.ContainsValue("value-b"));
            Assert.AreEqual("auth", config.Authentication);

            config = ClientConfigurationHelper.GetConfigurationForClient(LeverConfiguration, "client-no-auth");
            Assert.IsNotNull(config);
            Assert.IsNull(config.Authentication);
        }