public void AddOAuthServiceOptions_WithServiceName_NoVCAPs_ThrowsConnectorException() { IServiceCollection services = new ServiceCollection(); var config = new ConfigurationBuilder().Build(); var ex = Assert.Throws <ConnectorException>(() => OAuthServiceCollectionExtensions.AddOAuthServiceOptions(services, config, "foobar")); Assert.Contains("foobar", ex.Message); }
public void AddOAuthServiceOptions_ThrowsIfServiceNameNull() { IServiceCollection services = new ServiceCollection(); IConfigurationRoot config = null; string serviceName = null; var ex = Assert.Throws <ArgumentNullException>(() => OAuthServiceCollectionExtensions.AddOAuthServiceOptions(services, config, serviceName)); Assert.Contains(nameof(serviceName), ex.Message); }
public void AddOAuthServiceOptions_WithVCAPs_AddsOAuthOptions() { // Arrange var env2 = @" { 'p-identity': [ { 'credentials': { 'client_id': 'cb3efc76-bd22-46b3-a5ca-3aaa21c96073', 'client_secret': '92b5ebf0-c67b-4671-98d3-8e316fb11e30', 'auth_domain': 'https://sso.login.system.testcloud.com' }, 'syslog_drain_url': null, 'label': 'p-identity', 'provider': null, 'plan': 'sso', 'name': 'mySSO', 'tags': [] } ] } "; // Arrange IServiceCollection services = new ServiceCollection(); Environment.SetEnvironmentVariable("VCAP_APPLICATION", TestHelpers.VCAP_APPLICATION); Environment.SetEnvironmentVariable("VCAP_SERVICES", env2); ConfigurationBuilder builder = new ConfigurationBuilder(); builder.AddCloudFoundry(); var config = builder.Build(); // Act and Assert OAuthServiceCollectionExtensions.AddOAuthServiceOptions(services, config); var service = services.BuildServiceProvider().GetService <IOptions <OAuthServiceOptions> >(); Assert.NotNull(service); var opts = service.Value; Assert.NotNull(opts); Assert.Equal("cb3efc76-bd22-46b3-a5ca-3aaa21c96073", opts.ClientId); Assert.Equal("92b5ebf0-c67b-4671-98d3-8e316fb11e30", opts.ClientSecret); Assert.Equal("https://sso.login.system.testcloud.com" + OAuthConnectorDefaults.Default_AccessTokenUri, opts.AccessTokenUrl); Assert.Equal("https://sso.login.system.testcloud.com" + OAuthConnectorDefaults.Default_JwtTokenKey, opts.JwtKeyUrl); Assert.Equal("https://sso.login.system.testcloud.com" + OAuthConnectorDefaults.Default_CheckTokenUri, opts.TokenInfoUrl); Assert.Equal("https://sso.login.system.testcloud.com" + OAuthConnectorDefaults.Default_AuthorizationUri, opts.UserAuthorizationUrl); Assert.Equal("https://sso.login.system.testcloud.com" + OAuthConnectorDefaults.Default_UserInfoUri, opts.UserInfoUrl); Assert.NotNull(opts.Scope); Assert.Equal(0, opts.Scope.Count); }
public void AddOAuthServiceOptions_NoVCAPs_AddsOAuthOptions() { IServiceCollection services = new ServiceCollection(); var config = new ConfigurationBuilder().Build(); OAuthServiceCollectionExtensions.AddOAuthServiceOptions(services, config); var service = services.BuildServiceProvider().GetService <IOptions <OAuthServiceOptions> >(); Assert.NotNull(service); }
public void AddOAuthServiceOptions_MultipleOAuthServices_ThrowsConnectorException() { // Arrange var env2 = @" { 'p-identity': [ { 'credentials': { 'client_id': 'cb3efc76-bd22-46b3-a5ca-3aaa21c96073', 'client_secret': '92b5ebf0-c67b-4671-98d3-8e316fb11e30', 'auth_domain': 'https://sso.login.system.testcloud.com' }, 'syslog_drain_url': null, 'label': 'p-identity', 'provider': null, 'plan': 'sso', 'name': 'mySSO', 'tags': [] }, { 'credentials': { 'client_id': 'cb3efc76-bd22-46b3-a5ca-3aaa21c96073', 'client_secret': '92b5ebf0-c67b-4671-98d3-8e316fb11e30', 'auth_domain': 'https://sso.login.system.testcloud.com' }, 'syslog_drain_url': null, 'label': 'p-identity', 'provider': null, 'plan': 'sso', 'name': 'mySSO2', 'tags': [] } ] } "; // Arrange IServiceCollection services = new ServiceCollection(); Environment.SetEnvironmentVariable("VCAP_APPLICATION", TestHelpers.VCAP_APPLICATION); Environment.SetEnvironmentVariable("VCAP_SERVICES", env2); ConfigurationBuilder builder = new ConfigurationBuilder(); builder.AddCloudFoundry(); var config = builder.Build(); // Act and Assert var ex = Assert.Throws <ConnectorException>(() => OAuthServiceCollectionExtensions.AddOAuthServiceOptions(services, config)); Assert.Contains("Multiple", ex.Message); }
public void AddOAuthServiceOptions_ThrowsIfConfigurationNull() { IServiceCollection services = new ServiceCollection(); IConfigurationRoot config = null; var ex = Assert.Throws <ArgumentNullException>(() => OAuthServiceCollectionExtensions.AddOAuthServiceOptions(services, config)); Assert.Contains(nameof(config), ex.Message); var ex2 = Assert.Throws <ArgumentNullException>(() => OAuthServiceCollectionExtensions.AddOAuthServiceOptions(services, config, "foobar")); Assert.Contains(nameof(config), ex2.Message); }
public void AddOAuthServiceOptions_WithVCAPs_AddsOAuthOptions() { var env2 = @" { ""p-identity"": [{ ""credentials"": { ""client_id"": ""cb3efc76-bd22-46b3-a5ca-3aaa21c96073"", ""client_secret"": ""92b5ebf0-c67b-4671-98d3-8e316fb11e30"", ""auth_domain"": ""https://sso.login.system.testcloud.com"" }, ""syslog_drain_url"": null, ""label"": ""p-identity"", ""provider"": null, ""plan"": ""sso"", ""name"": ""mySSO"", ""tags"": [] }] }"; IServiceCollection services = new ServiceCollection(); Environment.SetEnvironmentVariable("VCAP_APPLICATION", TestHelpers.VCAP_APPLICATION); Environment.SetEnvironmentVariable("VCAP_SERVICES", env2); var builder = new ConfigurationBuilder(); builder.AddCloudFoundry(); var config = builder.Build(); OAuthServiceCollectionExtensions.AddOAuthServiceOptions(services, config); var service = services.BuildServiceProvider().GetService <IOptions <OAuthServiceOptions> >(); Assert.NotNull(service); var opts = service.Value; Assert.NotNull(opts); Assert.Equal("cb3efc76-bd22-46b3-a5ca-3aaa21c96073", opts.ClientId); Assert.Equal("92b5ebf0-c67b-4671-98d3-8e316fb11e30", opts.ClientSecret); Assert.Equal("https://sso.login.system.testcloud.com" + OAuthConnectorDefaults.Default_AccessTokenUri, opts.AccessTokenUrl); Assert.Equal("https://sso.login.system.testcloud.com" + OAuthConnectorDefaults.Default_JwtTokenKey, opts.JwtKeyUrl); Assert.Equal("https://sso.login.system.testcloud.com" + OAuthConnectorDefaults.Default_CheckTokenUri, opts.TokenInfoUrl); Assert.Equal("https://sso.login.system.testcloud.com" + OAuthConnectorDefaults.Default_AuthorizationUri, opts.UserAuthorizationUrl); Assert.Equal("https://sso.login.system.testcloud.com" + OAuthConnectorDefaults.Default_UserInfoUri, opts.UserInfoUrl); Assert.NotNull(opts.Scope); Assert.Equal(0, opts.Scope.Count); }
public void AddOAuthServiceOptions_MultipleOAuthServices_ThrowsConnectorException() { // Arrange var env2 = @" { ""p-identity"": [{ ""credentials"": { ""client_id"": ""cb3efc76-bd22-46b3-a5ca-3aaa21c96073"", ""client_secret"": ""92b5ebf0-c67b-4671-98d3-8e316fb11e30"", ""auth_domain"": ""https://sso.login.system.testcloud.com"" }, ""syslog_drain_url"": null, ""label"": ""p-identity"", ""provider"": null, ""plan"": ""sso"", ""name"": ""mySSO"", ""tags"": [] }, { ""credentials"": { ""client_id"": ""cb3efc76-bd22-46b3-a5ca-3aaa21c96073"", ""client_secret"": ""92b5ebf0-c67b-4671-98d3-8e316fb11e30"", ""auth_domain"": ""https://sso.login.system.testcloud.com"" }, ""syslog_drain_url"": null, ""label"": ""p-identity"", ""provider"": null, ""plan"": ""sso"", ""name"": ""mySSO2"", ""tags"": [] }] }"; // Arrange IServiceCollection services = new ServiceCollection(); Environment.SetEnvironmentVariable("VCAP_APPLICATION", TestHelpers.VCAP_APPLICATION); Environment.SetEnvironmentVariable("VCAP_SERVICES", env2); var builder = new ConfigurationBuilder(); builder.AddCloudFoundry(); var config = builder.Build(); // Act and Assert var ex = Assert.Throws <ConnectorException>(() => OAuthServiceCollectionExtensions.AddOAuthServiceOptions(services, config)); Assert.Contains("Multiple", ex.Message); }
public void AddOAuthServiceOptions_WithVCAPs_AddsOAuthOptions() { // Arrange var env1 = @" { 'limits': { 'fds': 16384, 'mem': 1024, 'disk': 1024 }, 'application_name': 'spring-cloud-broker', 'application_uris': [ 'spring-cloud-broker.apps.testcloud.com' ], 'name': 'spring-cloud-broker', 'space_name': 'p-spring-cloud-services', 'space_id': '65b73473-94cc-4640-b462-7ad52838b4ae', 'uris': [ 'spring-cloud-broker.apps.testcloud.com' ], 'users': null, 'version': '07e112f7-2f71-4f5a-8a34-db51dbed30a3', 'application_version': '07e112f7-2f71-4f5a-8a34-db51dbed30a3', 'application_id': '798c2495-fe75-49b1-88da-b81197f2bf06' } }"; var env2 = @" { 'p-identity': [ { 'credentials': { 'client_id': 'cb3efc76-bd22-46b3-a5ca-3aaa21c96073', 'client_secret': '92b5ebf0-c67b-4671-98d3-8e316fb11e30', 'auth_domain': 'https://sso.login.system.testcloud.com' }, 'syslog_drain_url': null, 'label': 'p-identity', 'provider': null, 'plan': 'sso', 'name': 'mySSO', 'tags': [] } ] } "; // Arrange IServiceCollection services = new ServiceCollection(); Environment.SetEnvironmentVariable("VCAP_APPLICATION", env1); Environment.SetEnvironmentVariable("VCAP_SERVICES", env2); ConfigurationBuilder builder = new ConfigurationBuilder(); builder.AddCloudFoundry(); var config = builder.Build(); // Act and Assert OAuthServiceCollectionExtensions.AddOAuthServiceOptions(services, config); var service = services.BuildServiceProvider().GetService <IOptions <OAuthServiceOptions> >(); Assert.NotNull(service); var opts = service.Value; Assert.NotNull(opts); Assert.Equal("cb3efc76-bd22-46b3-a5ca-3aaa21c96073", opts.ClientId); Assert.Equal("92b5ebf0-c67b-4671-98d3-8e316fb11e30", opts.ClientSecret); Assert.Equal("https://sso.login.system.testcloud.com" + OAuthConnectorDefaults.Default_AccessTokenUri, opts.AccessTokenUrl); Assert.Equal("https://sso.login.system.testcloud.com" + OAuthConnectorDefaults.Default_JwtTokenKey, opts.JwtKeyUrl); Assert.Equal("https://sso.login.system.testcloud.com" + OAuthConnectorDefaults.Default_CheckTokenUri, opts.TokenInfoUrl); Assert.Equal("https://sso.login.system.testcloud.com" + OAuthConnectorDefaults.Default_AuthorizationUri, opts.UserAuthorizationUrl); Assert.Equal("https://sso.login.system.testcloud.com" + OAuthConnectorDefaults.Default_UserInfoUri, opts.UserInfoUrl); Assert.NotNull(opts.Scope); Assert.Equal(0, opts.Scope.Count); }
public void AddOAuthServiceOptions_MultipleOAuthServices_ThrowsConnectorException() { // Arrange var env1 = @" { 'limits': { 'fds': 16384, 'mem': 1024, 'disk': 1024 }, 'application_name': 'spring-cloud-broker', 'application_uris': [ 'spring-cloud-broker.apps.testcloud.com' ], 'name': 'spring-cloud-broker', 'space_name': 'p-spring-cloud-services', 'space_id': '65b73473-94cc-4640-b462-7ad52838b4ae', 'uris': [ 'spring-cloud-broker.apps.testcloud.com' ], 'users': null, 'version': '07e112f7-2f71-4f5a-8a34-db51dbed30a3', 'application_version': '07e112f7-2f71-4f5a-8a34-db51dbed30a3', 'application_id': '798c2495-fe75-49b1-88da-b81197f2bf06' } }"; var env2 = @" { 'p-identity': [ { 'credentials': { 'client_id': 'cb3efc76-bd22-46b3-a5ca-3aaa21c96073', 'client_secret': '92b5ebf0-c67b-4671-98d3-8e316fb11e30', 'auth_domain': 'https://sso.login.system.testcloud.com' }, 'syslog_drain_url': null, 'label': 'p-identity', 'provider': null, 'plan': 'sso', 'name': 'mySSO', 'tags': [] }, { 'credentials': { 'client_id': 'cb3efc76-bd22-46b3-a5ca-3aaa21c96073', 'client_secret': '92b5ebf0-c67b-4671-98d3-8e316fb11e30', 'auth_domain': 'https://sso.login.system.testcloud.com' }, 'syslog_drain_url': null, 'label': 'p-identity', 'provider': null, 'plan': 'sso', 'name': 'mySSO2', 'tags': [] } ] } "; // Arrange IServiceCollection services = new ServiceCollection(); Environment.SetEnvironmentVariable("VCAP_APPLICATION", env1); Environment.SetEnvironmentVariable("VCAP_SERVICES", env2); ConfigurationBuilder builder = new ConfigurationBuilder(); builder.AddCloudFoundry(); var config = builder.Build(); // Act and Assert var ex = Assert.Throws <ConnectorException>(() => OAuthServiceCollectionExtensions.AddOAuthServiceOptions(services, config)); Assert.Contains("Multiple", ex.Message); }