コード例 #1
0
        public void EntryCollection_IndexerReadByTitle()
        {
            var doc = new PwSafe.Document("Password");

            Assert.NotEqual(Guid.Empty, doc.Entries["A"].Uuid);
            Assert.Equal("A", doc.Entries["A"].Title);
        }
コード例 #2
0
        public void EntryCollection_New()
        {
            var doc = new PwSafe.Document("Password");

            doc.Entries.Add(new PwSafe.Entry("Test"));

            Assert.Equal("Test", doc.Entries[0].Title);
        }
コード例 #3
0
        public void RecordCollection_ReadOnly_IndexerRead()
        {
            var doc = new PwSafe.Document("Password");

            doc.Entries.Add(new PwSafe.Entry());
            doc.IsReadOnly = true;
            Assert.Equal("", doc.Entries[0].Records[PwSafe.RecordType.Title].Text);
        }
コード例 #4
0
 public void RecordCollection_ReadOnly_IndexerWrite()
 {
     Assert.Throws <NotSupportedException>(() => {
         var doc = new PwSafe.Document("Password");
         doc.Entries.Add(new PwSafe.Entry());
         doc.IsReadOnly = true;
         doc.Entries[0].Records[PwSafe.RecordType.Title] = null;
     });
 }
コード例 #5
0
 public void EntryCollection_ReadOnly_IndexerWrite4()
 {
     Assert.Throws <NotSupportedException>(() => {
         var doc = new PwSafe.Document("Password");
         doc.Entries.Add(new PwSafe.Entry("X.Y", "A"));
         doc.IsReadOnly = true;
         doc.Entries["X.Y", "A", PwSafe.RecordType.EmailAddress] = null;
     });
 }
コード例 #6
0
 public void RecordCollection_ReadOnly()
 {
     Assert.Throws <NotSupportedException>(() => {
         var doc = new PwSafe.Document("Password");
         doc.Entries.Add(new PwSafe.Entry());
         doc.IsReadOnly = true;
         doc.Entries[0].Records.Add(new PwSafe.Record(PwSafe.RecordType.Group));
     });
 }
コード例 #7
0
ファイル: RecordTests.cs プロジェクト: medo64/PasswordSafe
        public void Record_ReadOnly()
        {
            Assert.Throws <NotSupportedException>(() => {
                var doc = new PwSafe.Document("Password");
                doc.Entries["Test"].Password = "******";

                doc.IsReadOnly = true;
                doc.Entries[0].Records[PwSafe.RecordType.Password].Text = "New";
            });
        }
コード例 #8
0
 public void Header_ReadOnly_IndexerWrite()
 {
     Assert.Throws <NotSupportedException>(() => {
         var doc = new PwSafe.Document("Password")
         {
             IsReadOnly = true
         };
         doc.Headers[PwSafe.HeaderType.DatabaseName] = null;
     });
 }
コード例 #9
0
        public void Header_ReadOnly_IndexerRead()
        {
            var doc = new PwSafe.Document("Password")
            {
                IsReadOnly = true
            };

            Assert.NotNull(doc.Headers[PwSafe.HeaderType.DatabaseName]);
            Assert.Equal("", doc.Headers[PwSafe.HeaderType.DatabaseName].Text);
        }
コード例 #10
0
        public void EntryCollection_IndexerReadByTitleNonEmpty()
        {
            var doc = new PwSafe.Document("Password");

            doc.Entries.Add(new PwSafe.Entry("A"));
            Assert.Equal("A", doc.Entries["A"].Title);

            doc.Entries["A"].Title = "B";
            Assert.Equal("B", doc.Entries["B"].Title);
        }
コード例 #11
0
 public void EntryCollection_ReadOnly_IndexerWrite()
 {
     Assert.Throws <NotSupportedException>(() => {
         var doc = new PwSafe.Document("Password")
         {
             IsReadOnly = true
         };
         doc.Entries["A"] = new PwSafe.Entry();
     });
 }
コード例 #12
0
ファイル: EntryTests.cs プロジェクト: medo64/PasswordSafe
        public void Entry_Clone_Document()
        {
            var doc = new PwSafe.Document("Password");

            doc.Entries.Add(new PwSafe.Entry("Test"));
            doc.Save(new MemoryStream());

            doc.Entries[0].Clone();
            Assert.False(doc.HasChanged);
        }
コード例 #13
0
        public void EntryCollection_IndexerReadByGroupTitleType()
        {
            var doc = new PwSafe.Document("Password");

            Assert.NotEqual(Guid.Empty, doc.Entries["X.Y", "A", PwSafe.RecordType.Uuid].Uuid);
            Assert.Equal("X.Y", doc.Entries["X.Y", "A", PwSafe.RecordType.Group].Text);
            Assert.Equal("A", doc.Entries["X.Y", "A", PwSafe.RecordType.Title].Text);
            Assert.NotEqual(Guid.Empty, doc.Entries["X.Y", "A"][PwSafe.RecordType.Uuid].Uuid);
            Assert.Equal("A", doc.Entries["X.Y", "A"][PwSafe.RecordType.Title].Text);
        }
コード例 #14
0
        public void Entry_AccessByRecordType()
        {
            var doc = new PwSafe.Document("Password");

            doc.Entries["Test"].Password = "******";
            Assert.True(doc.Entries["Test"][PwSafe.RecordType.Uuid].Uuid != Guid.Empty);
            Assert.Equal("Old", doc.Entries["Test"][PwSafe.RecordType.Password].Text);

            doc.Entries["Test"][PwSafe.RecordType.Password].Text = "New";
            Assert.Equal("New", doc.Entries["Test"][PwSafe.RecordType.Password].Text);
        }
コード例 #15
0
        public void HeaderCollection_New()
        {
            var doc = new PwSafe.Document("Password");

            doc.Headers.Add(new PwSafe.Header(PwSafe.HeaderType.DatabaseName)
            {
                Text = "Test"
            });

            Assert.Equal("Test", doc.Name);
        }
コード例 #16
0
        public void EntryCollection_ReadOnly_IndexerRead()
        {
            var doc = new PwSafe.Document("Password")
            {
                IsReadOnly = true
            };

            Assert.NotNull(doc.Entries["Test"]);
            Assert.Equal("", doc.Entries["Test"].Title);
            Assert.NotNull(doc.Entries["Test", PwSafe.RecordType.Title]);
            Assert.Equal("", doc.Entries["Test", PwSafe.RecordType.Title].Text);
        }
コード例 #17
0
        public void RecordCollection_New()
        {
            var doc = new PwSafe.Document("Password");

            doc.Entries.Add(new PwSafe.Entry());
            doc.Entries[0].Records.Add(new PwSafe.Record(PwSafe.RecordType.Group)
            {
                Text = "Test"
            });

            Assert.True(string.Equals("Test", doc.Entries[0].Group, StringComparison.Ordinal));
        }
コード例 #18
0
        public void Header_ReadOnly()
        {
            Assert.Throws <NotSupportedException>(() => {
                var doc = new PwSafe.Document("Password");
                doc.Headers.Add(new PwSafe.Header(PwSafe.HeaderType.DatabaseName)
                {
                    Text = "Test"
                });

                doc.IsReadOnly = true;
                doc.Headers[PwSafe.HeaderType.DatabaseName].Text = "NewName";
            });
        }
コード例 #19
0
        public void EntryCollection_IndexerReadByGroupTitleTypeNonEmpty()
        {
            var doc = new PwSafe.Document("Password");

            doc.Entries.Add(new PwSafe.Entry("X.Y", "A"));
            Assert.Equal("X.Y", doc.Entries["A"][PwSafe.RecordType.Group].Text);
            Assert.Equal("A", doc.Entries["A"][PwSafe.RecordType.Title].Text);

            doc.Entries["A"].Group = doc.Entries["A"].Group.Up();
            doc.Entries["A"].Title = "B";
            Assert.Equal("X", doc.Entries["B"][PwSafe.RecordType.Group].Text);
            Assert.Equal("B", doc.Entries["B"][PwSafe.RecordType.Title].Text);
        }
コード例 #20
0
ファイル: App.cs プロジェクト: medo64/PasswordSafe
        private static void Show(PwSafe.Document doc, ConsoleColor color)
        {
            Console.ForegroundColor = color;

            Console.WriteLine("Headers");
            foreach (var field in doc.Headers)
            {
                Console.WriteLine("    {0}: {1}", field.HeaderType, field.ToString());
            }
            Console.WriteLine();

            Console.WriteLine("Entries");
            foreach (var entry in doc.Entries)
            {
                Console.WriteLine("    {0}:", entry.ToString());
                foreach (var field in entry.Records)
                {
                    Console.WriteLine("        {0}: {1}", field.RecordType, field.ToString());
                }
                Console.WriteLine();
            }

            Console.ResetColor();
        }
コード例 #21
0
        public void Entry_TestNamed()
        {
            var guid = Guid.NewGuid();

            var doc = new PwSafe.Document("Password")
            {
                TrackAccess = false, TrackModify = false
            };
            var entry = new PwSafe.Entry();

            doc.Entries.Add(entry);

            entry.Uuid                     = guid;
            entry.Group                    = "Group";
            entry.Title                    = "Title";
            entry.UserName                 = "******";
            entry.Notes                    = "Notes";
            entry.Password                 = "******";
            entry.CreationTime             = new DateTime(2001, 1, 1, 0, 0, 0, DateTimeKind.Utc);
            entry.PasswordModificationTime = new DateTime(2002, 1, 1, 0, 0, 0, DateTimeKind.Utc);
            entry.LastAccessTime           = new DateTime(2003, 1, 1, 0, 0, 0, DateTimeKind.Utc);
            entry.PasswordExpiryTime       = new DateTime(2004, 1, 1, 0, 0, 0, DateTimeKind.Utc);
            entry.LastModificationTime     = new DateTime(2005, 1, 1, 0, 0, 0, DateTimeKind.Utc);
            entry.Url                         = "http://example.com";
            entry.Email                       = "*****@*****.**";
            entry.TwoFactorKey                = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
            entry.CreditCardNumber            = "1234 5678 9012 3456";
            entry.CreditCardExpiration        = "Title";
            entry.CreditCardVerificationValue = "0987";
            entry.CreditCardPin               = "6543";
            entry.QRCode                      = "https://medo64.com/";

            Assert.Equal(guid, entry.Uuid);
            Assert.Equal("Group", (string)entry.Group);
            Assert.Equal("Title", entry.Title);
            Assert.Equal("UserName", entry.UserName);
            Assert.Equal("Notes", entry.Notes);
            Assert.Equal("Password", entry.Password);
            Assert.Equal(new DateTime(2001, 1, 1, 0, 0, 0, DateTimeKind.Utc), entry.CreationTime);
            Assert.Equal(new DateTime(2002, 1, 1, 0, 0, 0, DateTimeKind.Utc), entry.PasswordModificationTime);
            Assert.Equal(new DateTime(2003, 1, 1, 0, 0, 0, DateTimeKind.Utc), entry.LastAccessTime);
            Assert.Equal(new DateTime(2004, 1, 1, 0, 0, 0, DateTimeKind.Utc), entry.PasswordExpiryTime);
            Assert.Equal(new DateTime(2005, 1, 1, 0, 0, 0, DateTimeKind.Utc), entry.LastModificationTime);
            Assert.Equal("http://example.com", entry.Url);
            Assert.Equal("*****@*****.**", entry.Email);
            Assert.Equal("00-01-02-03-04-05-06-07-08-09", BitConverter.ToString(entry.TwoFactorKey));
            Assert.Equal("1234 5678 9012 3456", entry.CreditCardNumber);
            Assert.Equal("Title", entry.CreditCardExpiration);
            Assert.Equal("0987", entry.CreditCardVerificationValue);
            Assert.Equal("6543", entry.CreditCardPin);
            Assert.Equal("https://medo64.com/", entry.QRCode);

            Assert.Equal(guid, entry[PwSafe.RecordType.Uuid].Uuid);
            Assert.Equal("Group", entry[PwSafe.RecordType.Group].Text);
            Assert.Equal("Title", entry[PwSafe.RecordType.Title].Text);
            Assert.Equal("UserName", entry[PwSafe.RecordType.UserName].Text);
            Assert.Equal("Notes", entry[PwSafe.RecordType.Notes].Text);
            Assert.Equal("Password", entry[PwSafe.RecordType.Password].Text);
            Assert.Equal(new DateTime(2001, 1, 1, 0, 0, 0, DateTimeKind.Utc), entry[PwSafe.RecordType.CreationTime].Time);
            Assert.Equal(new DateTime(2002, 1, 1, 0, 0, 0, DateTimeKind.Utc), entry[PwSafe.RecordType.PasswordModificationTime].Time);
            Assert.Equal(new DateTime(2003, 1, 1, 0, 0, 0, DateTimeKind.Utc), entry[PwSafe.RecordType.LastAccessTime].Time);
            Assert.Equal(new DateTime(2004, 1, 1, 0, 0, 0, DateTimeKind.Utc), entry[PwSafe.RecordType.PasswordExpiryTime].Time);
            Assert.Equal(new DateTime(2005, 1, 1, 0, 0, 0, DateTimeKind.Utc), entry[PwSafe.RecordType.LastModificationTime].Time);
            Assert.Equal("http://example.com", entry[PwSafe.RecordType.Url].Text);
            Assert.Equal("*****@*****.**", entry[PwSafe.RecordType.EmailAddress].Text);
            Assert.Equal("00-01-02-03-04-05-06-07-08-09", BitConverter.ToString(entry[PwSafe.RecordType.TwoFactorKey].GetBytes()));
            Assert.Equal("1234 5678 9012 3456", entry[PwSafe.RecordType.CreditCardNumber].Text);
            Assert.Equal("Title", entry[PwSafe.RecordType.CreditCardExpiration].Text);
            Assert.Equal("0987", entry[PwSafe.RecordType.CreditCardVerificationValue].Text);
            Assert.Equal("6543", entry[PwSafe.RecordType.CreditCardPin].Text);
            Assert.Equal("https://medo64.com/", entry[PwSafe.RecordType.QRCode].Text);
        }