Ejemplo n.º 1
0
        public async Task ThrowsKeyNotFoundExceptionWhenKeyNotFound()
        {
            using (var credentialCache = new CredentialCache())
            {
                await Assert.ThrowsAsync <KeyNotFoundException>(
                    async() => await credentialCache.Invalidate("git:_"));

                await Assert.ThrowsAsync <KeyNotFoundException>(
                    async() => await credentialCache.Invalidate("_"));
            }
        }
        public async Task RetrievesValueWithAlternateKeys()
        {
            const string key = nameof(RetrievesValueWithAlternateKeys);
            using (var credentialCache = new CredentialCache())
            {
                try
                {
                    var credential = Tuple.Create("somebody", "somebody's secret");
                    await credentialCache.InsertObject(key, credential);

                    var retrieved = await credentialCache.GetObject<Tuple<string, string>>(key);

                    Assert.Equal("somebody", retrieved.Item1);
                    Assert.Equal("somebody's secret", retrieved.Item2);

                    var retrieved2 = await credentialCache.GetObject<Tuple<string, string>>("git:" + key + "/");

                    Assert.Equal("somebody", retrieved2.Item1);
                    Assert.Equal("somebody's secret", retrieved2.Item2);

                    var retrieved3 = await credentialCache.GetObject<Tuple<string, string>>("login:"******"/");

                    Assert.Equal("somebody", retrieved3.Item1);
                    Assert.Equal("somebody's secret", retrieved3.Item2);
                }
                finally
                {
                    await credentialCache.Invalidate(key);
                }
            }
        }
Ejemplo n.º 3
0
        public async Task StoresCredentialForKeyAndGitKey()
        {
            using (var credentialCache = new CredentialCache())
            {
                try
                {
                    var credential = Tuple.Create("somebody", "somebody's secret");

                    await credentialCache.InsertObject(nameof(StoresCredentialForKeyAndGitKey), credential);

                    var retrieved = await credentialCache.GetObject <Tuple <string, string> >(nameof(StoresCredentialForKeyAndGitKey));

                    Assert.Equal("somebody", retrieved.Item1);
                    Assert.Equal("somebody's secret", retrieved.Item2);
                    var retrieved2 = await credentialCache.GetObject <Tuple <string, string> >("git:" + nameof(StoresCredentialForKeyAndGitKey));

                    Assert.Equal("somebody", retrieved2.Item1);
                    Assert.Equal("somebody's secret", retrieved2.Item2);
                }
                finally
                {
                    try
                    {
                        await credentialCache.Invalidate(nameof(StoresCredentialForKeyAndGitKey));
                    }
                    catch (Exception)
                    {
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public async Task RetrievesValueWithAlternateKeys()
        {
            const string key = nameof(RetrievesValueWithAlternateKeys);

            using (var credentialCache = new CredentialCache())
            {
                try
                {
                    var credential = Tuple.Create("somebody", "somebody's secret");
                    await credentialCache.InsertObject(key, credential);

                    var retrieved = await credentialCache.GetObject <Tuple <string, string> >(key);

                    Assert.Equal("somebody", retrieved.Item1);
                    Assert.Equal("somebody's secret", retrieved.Item2);

                    var retrieved2 = await credentialCache.GetObject <Tuple <string, string> >("git:" + key + "/");

                    Assert.Equal("somebody", retrieved2.Item1);
                    Assert.Equal("somebody's secret", retrieved2.Item2);

                    var retrieved3 = await credentialCache.GetObject <Tuple <string, string> >("login:"******"/");

                    Assert.Equal("somebody", retrieved3.Item1);
                    Assert.Equal("somebody's secret", retrieved3.Item2);
                }
                finally
                {
                    await credentialCache.Invalidate(key);
                }
            }
        }
Ejemplo n.º 5
0
 public async Task ThrowsObjectDisposedExceptionWhenDisposed()
 {
     using (var credentialCache = new CredentialCache())
     {
         credentialCache.Dispose();
         await Assert.ThrowsAsync <ObjectDisposedException>(
             async() => await credentialCache.Invalidate("_"));
     }
 }
Ejemplo n.º 6
0
        public async Task InvalidatesTheCredential()
        {
            using (var credentialCache = new CredentialCache())
            {
                var credential = Tuple.Create("somebody", "somebody's secret");
                await credentialCache.InsertObject(nameof(InvalidatesTheCredential), credential);

                await credentialCache.Invalidate(nameof(InvalidatesTheCredential));

                await Assert.ThrowsAsync <KeyNotFoundException>(async() => await credentialCache.Get(nameof(InvalidatesTheCredential)));
            }
        }
Ejemplo n.º 7
0
        public async Task InvalidatesTheCredential()
        {
            const string key = "TheInvalidateMethod.InvalidatesTheCredential";

            using (var credentialCache = new CredentialCache())
            {
                var credential = Tuple.Create("somebody", "somebody's secret");
                await credentialCache.InsertObject(key, credential);

                await credentialCache.Invalidate(key);

                await Assert.ThrowsAsync <KeyNotFoundException>(async() => await credentialCache.Get(key));
            }
        }
Ejemplo n.º 8
0
        public async Task RetrievesPasswordAsUnicodeBytes()
        {
            using (var credentialCache = new CredentialCache())
            {
                try
                {
                    var credential = Tuple.Create("somebody", "somebody's secret");
                    await credentialCache.InsertObject(nameof(RetrievesPasswordAsUnicodeBytes), credential);

                    var retrieved = await credentialCache.Get(nameof(RetrievesPasswordAsUnicodeBytes));

                    Assert.Equal("somebody's secret", Encoding.Unicode.GetString(retrieved));
                }
                finally
                {
                    await credentialCache.Invalidate(nameof(RetrievesPasswordAsUnicodeBytes));
                }
            }
        }
        public async Task StoresCredentialForKeyAndGitKey()
        {
            using (var credentialCache = new CredentialCache())
            {
                try
                {
                    var credential = Tuple.Create("somebody", "somebody's secret");

                    await credentialCache.InsertObject(nameof(StoresCredentialForKeyAndGitKey), credential);

                    var retrieved = await credentialCache.GetObject<Tuple<string, string>>(nameof(StoresCredentialForKeyAndGitKey));
                    Assert.Equal("somebody", retrieved.Item1);
                    Assert.Equal("somebody's secret", retrieved.Item2);
                    var retrieved2 = await credentialCache.GetObject<Tuple<string, string>>("git:" + nameof(StoresCredentialForKeyAndGitKey));
                    Assert.Equal("somebody", retrieved2.Item1);
                    Assert.Equal("somebody's secret", retrieved2.Item2);
                }
                finally
                {
                    try
                    {
                        await credentialCache.Invalidate(nameof(StoresCredentialForKeyAndGitKey));
                    }
                    catch (Exception)
                    {
                    }
                }
            }
        }
Ejemplo n.º 10
0
 public async Task ThrowsObjectDisposedExceptionWhenDisposed()
 {
     using (var credentialCache = new CredentialCache())
     {
         credentialCache.Dispose();
         await Assert.ThrowsAsync<ObjectDisposedException>(
             async () => await credentialCache.Invalidate("_"));
     }
 }
Ejemplo n.º 11
0
 public async Task ThrowsKeyNotFoundExceptionWhenKeyNotFound()
 {
     using (var credentialCache = new CredentialCache())
     {
         await Assert.ThrowsAsync<KeyNotFoundException>(
             async () => await credentialCache.Invalidate("git:_"));
         await Assert.ThrowsAsync<KeyNotFoundException>(
             async () => await credentialCache.Invalidate("_"));
     }
 }
Ejemplo n.º 12
0
        public async Task InvalidatesTheCredential()
        {
            using (var credentialCache = new CredentialCache())
            {
                var credential = Tuple.Create("somebody", "somebody's secret");
                await credentialCache.InsertObject(nameof(InvalidatesTheCredential), credential);
                await credentialCache.Invalidate(nameof(InvalidatesTheCredential));

                await Assert.ThrowsAsync<KeyNotFoundException>(async () => await credentialCache.Get(nameof(InvalidatesTheCredential)));
            }
        }
Ejemplo n.º 13
0
        public async Task RetrievesPasswordAsUnicodeBytes()
        {
            using (var credentialCache = new CredentialCache())
            {
                try
                {
                    var credential = Tuple.Create("somebody", "somebody's secret");
                    await credentialCache.InsertObject(nameof(RetrievesPasswordAsUnicodeBytes), credential);

                    var retrieved = await credentialCache.Get(nameof(RetrievesPasswordAsUnicodeBytes));

                    Assert.Equal("somebody's secret", Encoding.Unicode.GetString(retrieved));
                }
                finally
                {
                    await credentialCache.Invalidate(nameof(RetrievesPasswordAsUnicodeBytes));
                }
            }
        }
 public async Task InvalidatesTheCredential()
 {
     const string key = "TheInvalidateMethod.InvalidatesTheCredential";
     using (var credentialCache = new CredentialCache())
     {
         var credential = Tuple.Create("somebody", "somebody's secret");
         await credentialCache.InsertObject(key, credential);
         await credentialCache.Invalidate(key);
         await Assert.ThrowsAsync<KeyNotFoundException>(async () => await credentialCache.Get(key));
     }
 }