Ejemplo n.º 1
0
        protected override Task <bool> RunInternalAsync(StringBuilder log, IList <string> additionalFiles)
        {
            log.AppendLine($"ICredentialStore instance is of type: {_credentialStore.GetType().Name}");

            // Create a service that is guaranteed to be unique
            string       service  = $"https://example.com/{Guid.NewGuid():N}";
            const string account  = "john.doe";
            const string password = "******"; // [SuppressMessage("Microsoft.Security", "CS001:SecretInline", Justification="Fake credential")]

            try
            {
                log.Append("Writing test credential...");
                _credentialStore.AddOrUpdate(service, account, password);
                log.AppendLine(" OK");

                log.Append("Reading test credential...");
                ICredential outCredential = _credentialStore.Get(service, account);
                if (outCredential is null)
                {
                    log.AppendLine(" Failed");
                    log.AppendLine("Test credential object is null!");
                    return(Task.FromResult(false));
                }

                log.AppendLine(" OK");

                if (!StringComparer.Ordinal.Equals(account, outCredential.Account))
                {
                    log.Append("Test credential account did not match!");
                    log.AppendLine($"Expected: {account}");
                    log.AppendLine($"Actual: {outCredential.Account}");
                    return(Task.FromResult(false));
                }

                if (!StringComparer.Ordinal.Equals(password, outCredential.Password))
                {
                    log.Append("Test credential password did not match!");
                    log.AppendLine($"Expected: {password}");
                    log.AppendLine($"Actual: {outCredential.Password}");
                    return(Task.FromResult(false));
                }
            }
            finally
            {
                log.Append("Deleting test credential...");
                _credentialStore.Remove(service, account);
                log.AppendLine(" OK");
            }

            return(Task.FromResult(true));
        }
Ejemplo n.º 2
0
 public void AddOrUpdate(string service, string account, string secret)
 {
     EnsureBackingStore();
     _backingStore.AddOrUpdate(service, account, secret);
 }
Ejemplo n.º 3
0
 public void AddOrUpdate(string key, ICredential credential)
 {
     EnsureBackingStore();
     _backingStore.AddOrUpdate(key, credential);
 }