public void TestPropertySettersAndGetters() { MockAppConfig config = new MockAppConfig(); config.MockReadSettings(dictSettings); provider = new OAuth2ProviderForServiceAccounts(config) { HttpClientFactory = mockHttpClientFactory, Clock = mockClock, ClientId = TEST_CLIENT_ID }; Assert.AreEqual(provider.ClientId, TEST_CLIENT_ID); provider.ClientSecret = TEST_CLIENT_SECRET; Assert.AreEqual(provider.ClientSecret, TEST_CLIENT_SECRET); provider.AccessToken = TEST_ACCESS_TOKEN; Assert.AreEqual(provider.AccessToken, TEST_ACCESS_TOKEN); provider.Scope = TEST_SCOPE; Assert.AreEqual(provider.Scope, TEST_SCOPE); provider.State = TEST_STATE; Assert.AreEqual(provider.State, TEST_STATE); provider.OnOAuthTokensObtained = TEST_CALLBACK; Assert.AreEqual(provider.OnOAuthTokensObtained, TEST_CALLBACK); }
public void TestReadSettings() { MockAppConfig config = new MockAppConfig(); config.MockReadSettings(tblSettings); NetworkCredential credential = (NetworkCredential)config.Proxy.Credentials; Assert.AreEqual(tblSettings["ProxyUser"].ToString(), credential.UserName); Assert.AreEqual(tblSettings["ProxyPassword"].ToString(), credential.Password); Assert.AreEqual(tblSettings["ProxyDomain"].ToString(), credential.Domain); Assert.AreEqual(bool.Parse(tblSettings["MaskCredentials"].ToString()), config.MaskCredentials); Assert.AreEqual(int.Parse(tblSettings["Timeout"].ToString()), config.Timeout); Assert.AreEqual(int.Parse(tblSettings["RetryCount"].ToString()), config.RetryCount); Assert.AreEqual(tblSettings["OAuth2ClientId"].ToString(), config.OAuth2ClientId); Assert.AreEqual(tblSettings["OAuth2ClientSecret"].ToString(), config.OAuth2ClientSecret); Assert.AreEqual(tblSettings["OAuth2ServiceAccountEmail"].ToString(), config.OAuth2ServiceAccountEmail); Assert.AreEqual(tblSettings["OAuth2PrnEmail"].ToString(), config.OAuth2PrnEmail); Assert.AreEqual(tblSettings["OAuth2AccessToken"].ToString(), config.OAuth2AccessToken); Assert.AreEqual(tblSettings["OAuth2RefreshToken"].ToString(), config.OAuth2RefreshToken); Assert.AreEqual(tblSettings["OAuth2Scope"].ToString(), config.OAuth2Scope); Assert.AreEqual(tblSettings["OAuth2RedirectUri"].ToString(), config.OAuth2RedirectUri); Assert.AreEqual(tblSettings["OAuth2JwtCertificatePath"].ToString(), config.OAuth2CertificatePath); Assert.AreEqual(tblSettings["OAuth2JwtCertificatePassword"].ToString(), config.OAuth2CertificatePassword); Assert.AreEqual(tblSettings["OAuth2Mode"].ToString(), config.OAuth2Mode.ToString()); Assert.AreEqual(bool.Parse(tblSettings["EnableGzipCompression"].ToString()), config.EnableGzipCompression); }
public void TestReadSettingsForDefaults() { Assert.DoesNotThrow(delegate() { MockAppConfig config = new MockAppConfig(); config.MockReadSettings(null); }); }
public void TestReadSettings() { MockAppConfig config = new MockAppConfig(); config.MockReadSettings(dictSettings); NetworkCredential credential = (NetworkCredential)config.Proxy.Credentials; Assert.AreEqual(dictSettings["ProxyUser"].ToString(), credential.UserName); Assert.AreEqual(dictSettings["ProxyPassword"].ToString(), credential.Password); Assert.AreEqual(dictSettings["ProxyDomain"].ToString(), credential.Domain); Assert.AreEqual(bool.Parse(dictSettings["MaskCredentials"].ToString()), config.MaskCredentials); Assert.AreEqual(int.Parse(dictSettings["Timeout"].ToString()), config.Timeout); Assert.AreEqual(int.Parse(dictSettings["RetryCount"].ToString()), config.RetryCount); Assert.AreEqual(dictSettings["OAuth2ClientId"].ToString(), config.OAuth2ClientId); Assert.AreEqual(dictSettings["OAuth2ClientSecret"].ToString(), config.OAuth2ClientSecret); Assert.AreEqual(dictSettings["OAuth2PrnEmail"].ToString(), config.OAuth2PrnEmail); Assert.AreEqual(dictSettings["OAuth2AccessToken"].ToString(), config.OAuth2AccessToken); Assert.AreEqual(dictSettings["OAuth2RefreshToken"].ToString(), config.OAuth2RefreshToken); Assert.AreEqual(dictSettings["OAuth2Scope"].ToString(), config.OAuth2Scope); Assert.AreEqual(dictSettings["OAuth2RedirectUri"].ToString(), config.OAuth2RedirectUri); Assert.AreEqual(dictSettings["OAuth2Mode"].ToString(), config.OAuth2Mode.ToString()); Assert.AreEqual(bool.Parse(dictSettings["EnableGzipCompression"].ToString()), config.EnableGzipCompression); // Since SettingWithNonEmptyDefaultValue is missing in dictSettings, default value should be // retained. Assert.AreEqual(MockAppConfig.TEST_DEFAULT_VALUE, config.SettingWithNonEmptyDefaultValue); }
public void TestGetAuthHeader() { MockAppConfig config = new MockAppConfig(); config.MockReadSettings(tblSettingsNoSecretJson); provider = new OAuth2ProviderForServiceAccounts(config); Assert.AreEqual(AUTHORIZATION_HEADER, provider.GetAuthHeader()); }
public void Init() { appConfig = new MockAppConfig(); appConfig.MockReadSettings(ALL_SETTINGS); newAppConfig = new MockAppConfig(); newAppConfig.MockReadSettings(ALL_SETTINGS_NEW); }
public void TestGetAuthHeader() { MockAppConfig config = new MockAppConfig(); config.MockReadSettings(dictSettings); provider = new OAuth2ProviderForServiceAccounts(config) { HttpClientFactory = mockHttpClientFactory, Clock = mockClock }; Assert.AreEqual(AUTHORIZATION_HEADER, provider.GetAuthHeader()); }
public void Init() { tblSettings = new Hashtable(); tblSettings.Add("OAuth2ClientId", "OAuth2ClientId"); tblSettings.Add("OAuth2ClientSecret", "OAuth2ClientSecret"); tblSettings.Add("OAuth2AccessToken", "OAuth2AccessToken"); tblSettings.Add("OAuth2RefreshToken", "OAuth2RefreshToken"); tblSettings.Add("OAuth2Scope", "OAuth2Scope"); tblSettings.Add("OAuth2RedirectUri", "OAuth2RedirectUri"); appConfig = new MockAppConfig(); appConfig.MockReadSettings(tblSettings); provider = new OAuth2ProviderForApplications(appConfig); oauth2RequestInterceptor.Intercept = true; }
public void TestConstructor() { MockAppConfig config = new MockAppConfig(); config.MockReadSettings(dictSettings); provider = new OAuth2ProviderForServiceAccounts(config); Assert.AreEqual(provider.ClientId, config.OAuth2ClientId); Assert.AreEqual(provider.ClientSecret, config.OAuth2ClientSecret); Assert.AreEqual(provider.AccessToken, config.OAuth2AccessToken); Assert.AreEqual(provider.Scope, config.OAuth2Scope); Assert.AreEqual(provider.ServiceAccountEmail, config.OAuth2ServiceAccountEmail); Assert.AreEqual(provider.PrnEmail, config.OAuth2PrnEmail); Assert.AreEqual(provider.JwtPrivateKey, config.OAuth2PrivateKey); Assert.AreEqual(provider.ServiceAccountEmail, config.OAuth2ServiceAccountEmail); }
public void TestPropertySettersAndGetters() { MockAppConfig config = new MockAppConfig(); config.MockReadSettings(tblSettingsNoSecretJson); provider = new OAuth2ProviderForServiceAccounts(config); provider.ClientId = TEST_CLIENT_ID; Assert.AreEqual(provider.ClientId, TEST_CLIENT_ID); provider.ClientSecret = TEST_CLIENT_SECRET; Assert.AreEqual(provider.ClientSecret, TEST_CLIENT_SECRET); provider.AccessToken = TEST_ACCESS_TOKEN; Assert.AreEqual(provider.AccessToken, TEST_ACCESS_TOKEN); provider.Scope = TEST_SCOPE; Assert.AreEqual(provider.Scope, TEST_SCOPE); provider.State = TEST_STATE; Assert.AreEqual(provider.State, TEST_STATE); provider.OnOAuthTokensObtained = TEST_CALLBACK; Assert.AreEqual(provider.OnOAuthTokensObtained, TEST_CALLBACK); provider.ServiceAccountEmail = TEST_SERVICE_ACCOUNT_EMAIL; Assert.AreEqual(provider.ServiceAccountEmail, TEST_SERVICE_ACCOUNT_EMAIL); provider.PrnEmail = TEST_PRN_EMAIL; Assert.AreEqual(provider.PrnEmail, TEST_PRN_EMAIL); provider.JwtCertificatePath = TEST_JWT_CERTIFICATE_PATH; Assert.AreEqual(provider.JwtCertificatePath, TEST_JWT_CERTIFICATE_PATH); provider.JwtCertificatePassword = TEST_JWT_CERTIFICATE_PASSWORD; Assert.AreEqual(provider.JwtCertificatePassword, TEST_JWT_CERTIFICATE_PASSWORD); provider.JwtPrivateKey = TEST_JWT_PRIVATE_KEY; Assert.AreEqual(provider.JwtPrivateKey, TEST_JWT_PRIVATE_KEY); }
public void Init() { tblSettings = new Hashtable(); tblSettings.Add("OAuth2ClientId", "OAuth2ClientId"); tblSettings.Add("OAuth2ClientSecret", "OAuth2ClientSecret"); tblSettings.Add("OAuth2ServiceAccountEmail", "OAuth2ServiceAccountEmail"); tblSettings.Add("OAuth2PrnEmail", "OAuth2PrnEmail"); tblSettings.Add("OAuth2AccessToken", "OAuth2AccessToken"); tblSettings.Add("OAuth2Scope", "OAuth2Scope"); tblSettings.Add("OAuth2RedirectUri", "OAuth2RedirectUri"); string tempCertificatePath = Path.GetTempFileName(); using (FileStream fs = File.OpenWrite(tempCertificatePath)) { fs.Write(Resources.certificate, 0, Resources.certificate.Length); } tblSettings.Add("OAuth2JwtCertificatePath", tempCertificatePath); tblSettings.Add("OAuth2JwtCertificatePassword", "notasecret"); appConfig = new MockAppConfig(); appConfig.MockReadSettings(tblSettings); provider = new OAuth2ProviderForServiceAccounts(appConfig); oauth2RequestInterceptor.Intercept = true; }