public void ShouldBeAbleToSetApiKeyResolver() { ProxyFactory serviceFactory = new ProxyFactory(".\\workspace_".RandomLetters(4), Logger); EncryptedEcho echo = serviceFactory.GetProxy <EncryptedEcho>(); ApiKeyResolver resolver = new ApiKeyResolver(); echo.Property("ApiKeyResolver", resolver); ApiKeyResolver got = echo.Property <ApiKeyResolver>("ApiKeyResolver"); Expect.AreSame(resolver, got); }
[UnitTest] // RegisterDb is defined in Program.cs public void ApiKey_ShouldCreateToken() { ClientTestSetup(); string methodName = MethodBase.GetCurrentMethod().Name; ApiKeyResolver resolver = new ApiKeyResolver(new LocalApiKeyProvider(), new TestApplicationNameProvider(methodName)); string data = "some random data"; string token = resolver.CreateKeyToken(data); Expect.IsNotNullOrEmpty(token, "Token was null or empty"); ClearApps(); }
public ApplicationRegistrationService(DataSettings dataSettings, AppConf conf, ApplicationRegistrationRepository coreRepo, ILogger logger) { ApplicationRegistrationRepository = coreRepo; ApplicationRegistrationRepository.WarningsAsErrors = false; dataSettings.SetDatabases(this); CompositeRepository = new CompositeRepository(ApplicationRegistrationRepository, dataSettings); _cacheManager = new CacheManager(100000000); _apiKeyResolver = new ApiKeyResolver(this, this); AppConf = conf; DataSettings = dataSettings; Logger = logger; HashAlgorithm = HashAlgorithms.SHA256; }
public CoreApplicationRegistrationService(CoreApplicationRegistryServiceConfig config, AppConf conf, ApplicationRegistrationRepository coreRepo, ILogger logger) { CoreRegistryRepository = coreRepo; CoreRegistryRepository.WarningsAsErrors = false; config.DatabaseProvider.SetDatabases(this); CompositeRepository = new CompositeRepository(CoreRegistryRepository, config.WorkspacePath); _cacheManager = new CacheManager(100000000); _apiKeyResolver = new ApiKeyResolver(this, this); AppConf = conf; Config = config; Logger = logger; HashAlgorithm = HashAlgorithms.SHA256; }
[UnitTest] // RegisterDb is defined in Program.cs public void ApiKey_ShouldSetToken() { ClientTestSetup(); string testName = MethodBase.GetCurrentMethod().Name; NameValueCollection nvc = new NameValueCollection(); string data = "Some random data"; IApiKeyProvider keyProvider = new LocalApiKeyProvider(); ApiKeyResolver resolver = new ApiKeyResolver(keyProvider, new TestApplicationNameProvider(testName)); resolver.SetKeyToken(nvc, data); Expect.IsNotNullOrEmpty(nvc[Headers.KeyToken], "Key token was not set"); ClearApps(); }
[UnitTest] // RegisterDb is defined in Program.cs public void ApiKey_ShouldSetValidToken() { ClientTestSetup(); string testName = MethodBase.GetCurrentMethod().Name; NameValueCollection nvc = new NameValueCollection(); string data = "Some random data"; IApiKeyProvider keyProvider = new LocalApiKeyProvider(); TestApplicationNameProvider nameProvider = new TestApplicationNameProvider(testName); ApiKeyResolver resolver = new ApiKeyResolver(keyProvider, nameProvider); resolver.SetKeyToken(nvc, data); string token = nvc[Headers.KeyToken]; bool isValid = resolver.IsValidKeyToken(data, token); Expect.IsTrue(isValid, "token was not valid"); ClearApps(); }
public void SecureServiceProxyInvokeWithApiKeyShouldSucceed() { CleanUp(); string methodName = MethodBase.GetCurrentMethod().Name; BamServer server; SecureChannel.Debug = true; string baseAddress; ServiceProxyTestHelpers.CreateServer(out baseAddress, out server); ServiceProxyTestHelpers.Servers.Add(server); // makes sure it gets stopped after test run SecureServiceProxyClient <ApiKeyRequiredEcho> sspc = new SecureServiceProxyClient <ApiKeyRequiredEcho>(baseAddress); IApplicationNameProvider nameProvider = new TestApplicationNameProvider(methodName); IApiKeyProvider keyProvider = new LocalApiKeyProvider(); ApiKeyResolver keyResolver = new ApiKeyResolver(keyProvider, nameProvider); SecureChannel channel = new SecureChannel(); channel.ApiKeyResolver = keyResolver; server.AddCommonService <SecureChannel>(channel); server.AddCommonService <ApiKeyRequiredEcho>(); server.Start(); string value = "InputValue_".RandomLetters(8); bool? thrown = false; sspc.InvocationException += (client, ex) => { thrown = true; }; sspc.ApiKeyResolver = keyResolver; string result = sspc.Invoke <string>("Send", new object[] { value }); Expect.IsFalse(thrown.Value, "Exception was thrown"); Expect.AreEqual(value, result); CleanUp(); }
public void SecureServiceProxyInvokeWithInvalidTokenShouldFail() { CleanUp(); BamServer server; SecureChannel.Debug = true; ServiceProxyTestHelpers.StartSecureChannelTestServerGetApiKeyRequiredEchoClient(out server, out SecureServiceProxyClient <ApiKeyRequiredEcho> sspc); string value = "InputValue_".RandomLetters(8); bool? thrown = false; sspc.InvocationException += (client, ex) => { thrown = true; }; ApiKeyResolver resolver = new ApiKeyResolver(new InvalidKeyProvider()); sspc.ApiKeyResolver = resolver; string result = sspc.Invoke <string>("Send", new object[] { value }); thrown.Value.IsTrue(); CleanUp(); }