Beispiel #1
0
        public void Evidence()
        {
            using (CaptureConsole) {
                var swid = new SoftwareIdentity();

                // add some data
                var evidence = swid.AddEvidence();

                var now = DateTime.Now;
                evidence.Date = now;

                evidence.DeviceId = "someid";

                var dir1 = evidence.AddDirectory("dir1");
                dir1.Location = "myapp";
                dir1.Root     = "PROGRAMFILES";
                dir1.IsKey    = false;

                // to xml
                var xml = XDocument.Parse(swid.SwidTagText);
                Console.WriteLine("SWID: {0} ", swid.SwidTagText);

                // assertions

                // verify only one element is actually created.
                Assert.Equal(evidence.ElementUniqueId, swid.AddEvidence().ElementUniqueId);

                // most is the same code as Payload...

                // check to make sure the object we got back is the same as we put in.
                dir1 = evidence.Directories.FirstOrDefault();
                Assert.Equal("dir1", dir1.Name);
                Assert.Equal("myapp", dir1.Location);
                Assert.Equal("PROGRAMFILES", dir1.Root);
                Assert.False(dir1.IsKey);

                Assert.Equal(now.ToUniversalTime(), ((DateTime)evidence.Date).ToUniversalTime());
                Assert.Equal("someid", evidence.DeviceId);

                // some xml validations:
                Assert.Equal("dir1", xml.XPathToAttribute("/swid:SoftwareIdentity/swid:Evidence/swid:Directory[1]/@name").Value);

                // check for the device id
                Assert.Equal("someid", xml.XPathToAttribute("/swid:SoftwareIdentity/swid:Evidence/@deviceId").Value);

                // validate the format of the date
                Assert.Equal(now.ToUniversalTime().ToString("o"), xml.XPathToAttribute("/swid:SoftwareIdentity/swid:Evidence/@date").Value);
            }
        }
Beispiel #2
0
        public void EmptyPayloadAndEvidence()
        {
            using (CaptureConsole) {
                var swid = new SoftwareIdentity();

                // add some data
                swid.AddPayload();
                swid.AddEvidence();

                // to xml
                var xml = XDocument.Parse(swid.SwidTagText);
                Console.WriteLine("SWID: {0} ", swid.SwidTagText);

                // assertions
                Assert.Empty(swid.Payload.Files);
                Assert.Empty(swid.Payload.Directories);
                Assert.Empty(swid.Payload.Processes);
                Assert.Empty(swid.Payload.Resources);

                Assert.Empty(swid.Evidence.Files);
                Assert.Empty(swid.Evidence.Directories);
                Assert.Empty(swid.Evidence.Processes);
                Assert.Empty(swid.Evidence.Resources);

                Assert.Empty(swid.Payload.Attributes.Values);
                Assert.Empty(swid.Evidence.Attributes.Keys);

                Assert.Null(swid.Evidence.Date);
                Assert.Null(swid.Evidence.DeviceId);
            }
        }
Beispiel #3
0
        public void EmptyPayloadAndEvidence()
        {
            using (CaptureConsole) {
                var swid = new SoftwareIdentity();

                // add some data
                swid.AddPayload();
                swid.AddEvidence();

                // to xml
                var xml = XDocument.Parse(swid.SwidTagText);
                Console.WriteLine("SWID: {0} ", swid.SwidTagText);

                // assertions
                Assert.Empty(swid.Payload.Files);
                Assert.Empty(swid.Payload.Directories);
                Assert.Empty(swid.Payload.Processes);
                Assert.Empty(swid.Payload.Resources);

                Assert.Empty(swid.Evidence.Files);
                Assert.Empty(swid.Evidence.Directories);
                Assert.Empty(swid.Evidence.Processes);
                Assert.Empty(swid.Evidence.Resources);

                Assert.Empty(swid.Payload.Attributes.Values);
                Assert.Empty(swid.Evidence.Attributes.Keys);

                Assert.Null(swid.Evidence.Date);
                Assert.Null(swid.Evidence.DeviceId);
            }
        }
Beispiel #4
0
        public void Evidence()
        {
            using (CaptureConsole) {
                var swid = new SoftwareIdentity();

                // add some data
                var evidence = swid.AddEvidence();

                var now = DateTime.Now;
                evidence.Date = now;

                evidence.DeviceId = "someid";

                var dir1 = evidence.AddDirectory("dir1");
                dir1.Location = "myapp";
                dir1.Root = "PROGRAMFILES";
                dir1.IsKey = false;

                // to xml
                var xml = XDocument.Parse(swid.SwidTagText);
                Console.WriteLine("SWID: {0} ", swid.SwidTagText);

                // assertions

                // verify only one element is actually created.
                Assert.Equal(evidence.ElementUniqueId, swid.AddEvidence().ElementUniqueId);

                // most is the same code as Payload...

                // check to make sure the object we got back is the same as we put in.
                dir1 = evidence.Directories.FirstOrDefault();
                Assert.Equal("dir1", dir1.Name);
                Assert.Equal("myapp", dir1.Location);
                Assert.Equal("PROGRAMFILES", dir1.Root);
                Assert.False(dir1.IsKey);

                Assert.Equal(now.ToUniversalTime(), ((DateTime)evidence.Date).ToUniversalTime());
                Assert.Equal("someid", evidence.DeviceId);

                // some xml validations:
                Assert.Equal("dir1", xml.XPathToAttribute("/swid:SoftwareIdentity/swid:Evidence/swid:Directory[1]/@name").Value);

                // check for the device id
                Assert.Equal("someid", xml.XPathToAttribute("/swid:SoftwareIdentity/swid:Evidence/@deviceId").Value);

                // validate the format of the date
                Assert.Equal(now.ToUniversalTime().ToString("o"), xml.XPathToAttribute("/swid:SoftwareIdentity/swid:Evidence/@date").Value);
            }
        }