Beispiel #1
0
    def testRegexForStringifiedValueMatchMatchesLabelsInList(self):
        labels_list = rdf_aff4.AFF4ObjectLabelsList()

        labels_list.AddLabel(rdf_aff4.AFF4ObjectLabel(name="ein", owner="GRR"))
        labels_list.AddLabel(
            rdf_aff4.AFF4ObjectLabel(name="zwei", owner="test"))
        labels_list.AddLabel(rdf_aff4.AFF4ObjectLabel(name="drei",
                                                      owner="GRR"))
        labels_list.AddLabel(
            rdf_aff4.AFF4ObjectLabel(name="vier", owner="test"))

        self.assertTrue(
            re.match(
                rdf_aff4.AFF4ObjectLabelsList.RegexForStringifiedValueMatch(
                    "ein"), str(labels_list)))
        self.assertTrue(
            re.match(
                rdf_aff4.AFF4ObjectLabelsList.RegexForStringifiedValueMatch(
                    "zwei"), str(labels_list)))
        self.assertTrue(
            re.match(
                rdf_aff4.AFF4ObjectLabelsList.RegexForStringifiedValueMatch(
                    "drei"), str(labels_list)))
        self.assertTrue(
            re.match(
                rdf_aff4.AFF4ObjectLabelsList.RegexForStringifiedValueMatch(
                    "vier"), str(labels_list)))
Beispiel #2
0
    def testStringifiedRepresentationIsSorted(self):
        labels_list = rdf_aff4.AFF4ObjectLabelsList()

        labels_list.AddLabel(rdf_aff4.AFF4ObjectLabel(name="foo", owner="GRR"))
        labels_list.AddLabel(rdf_aff4.AFF4ObjectLabel(name="bar",
                                                      owner="test"))

        self.assertEqual(utils.SmartStr(labels_list), "bar,foo")
Beispiel #3
0
    def testStringifiedValueIsLabelsNamesWithoutOwners(self):
        labels_list = rdf_aff4.AFF4ObjectLabelsList()

        labels_list.AddLabel(rdf_aff4.AFF4ObjectLabel(name="bar", owner="GRR"))
        labels_list.AddLabel(rdf_aff4.AFF4ObjectLabel(name="foo",
                                                      owner="test"))

        self.assertEqual(utils.SmartStr(labels_list), "bar,foo")
Beispiel #4
0
    def testAddLabelAddsLabelWithSameNameButDifferentOwner(self):
        labels_list = rdf_aff4.AFF4ObjectLabelsList()

        labels_list.AddLabel(rdf_aff4.AFF4ObjectLabel(name="foo",
                                                      owner="test"))
        self.assertEqual(len(labels_list.labels), 1)

        labels_list.AddLabel(rdf_aff4.AFF4ObjectLabel(name="foo", owner="GRR"))
        self.assertEqual(len(labels_list.labels), 2)
Beispiel #5
0
    def testStringifiedValueDoesNotHaveDuplicates(self):
        labels_list = rdf_aff4.AFF4ObjectLabelsList()

        labels_list.AddLabel(rdf_aff4.AFF4ObjectLabel(name="foo", owner="GRR"))
        labels_list.AddLabel(rdf_aff4.AFF4ObjectLabel(name="bar", owner="GRR"))
        labels_list.AddLabel(rdf_aff4.AFF4ObjectLabel(name="foo",
                                                      owner="test"))

        self.assertEqual(utils.SmartStr(labels_list), "bar,foo")
Beispiel #6
0
    def testAddLabelDoesNotAddLabelWithSameNameAndOwner(self):
        labels_list = rdf_aff4.AFF4ObjectLabelsList()

        labels_list.AddLabel(rdf_aff4.AFF4ObjectLabel(name="foo",
                                                      owner="test"))
        self.assertEqual(len(labels_list.labels), 1)

        labels_list.AddLabel(rdf_aff4.AFF4ObjectLabel(name="foo",
                                                      owner="test"))
        self.assertEqual(len(labels_list.labels), 1)
Beispiel #7
0
    def GenerateSample(self, number=0):
        label1 = rdf_aff4.AFF4ObjectLabel(
            name="foo_%d" % number,
            owner="test",
            timestamp=rdfvalue.RDFDatetime.FromSecondsSinceEpoch(42))

        label2 = rdf_aff4.AFF4ObjectLabel(
            name="bar_%d" % number,
            owner="test",
            timestamp=rdfvalue.RDFDatetime.FromSecondsSinceEpoch(42))

        return rdf_aff4.AFF4ObjectLabelsList(labels=[label1, label2])
Beispiel #8
0
    def testGetSortedLabelSet(self):
        labels_list = rdf_aff4.AFF4ObjectLabelsList()

        labels_list.AddLabel(rdf_aff4.AFF4ObjectLabel(name="foo",
                                                      owner="test"))
        labels_list.AddLabel(
            rdf_aff4.AFF4ObjectLabel(name="foo2", owner="test2"))
        labels_list.AddLabel(
            rdf_aff4.AFF4ObjectLabel(name="foo3", owner="test2"))

        self.assertItemsEqual(labels_list.GetLabelNames(),
                              ["foo", "foo2", "foo3"])
        self.assertItemsEqual(labels_list.GetLabelNames(owner="test2"),
                              ["foo2", "foo3"])
        self.assertEqual(labels_list.GetLabelNames(owner="test4"), [])
Beispiel #9
0
    def testRegexForStringifiedValueDoesNotMatchLabelsNotInList(self):
        labels_list = rdf_aff4.AFF4ObjectLabelsList()

        labels_list.AddLabel(rdf_aff4.AFF4ObjectLabel(name="ein", owner="GRR"))
        labels_list.AddLabel(
            rdf_aff4.AFF4ObjectLabel(name="zwei", owner="test"))
        self.assertFalse(
            re.match(
                rdf_aff4.AFF4ObjectLabelsList.RegexForStringifiedValueMatch(
                    "e"), str(labels_list)))
        self.assertFalse(
            re.match(
                rdf_aff4.AFF4ObjectLabelsList.RegexForStringifiedValueMatch(
                    "in"), str(labels_list)))
        self.assertFalse(
            re.match(
                rdf_aff4.AFF4ObjectLabelsList.RegexForStringifiedValueMatch(
                    "a.zwer"), str(labels_list)))
        self.assertFalse(
            re.match(
                rdf_aff4.AFF4ObjectLabelsList.RegexForStringifiedValueMatch(
                    "ein."), str(labels_list)))
Beispiel #10
0
 def testForwardSlashIsAllowed(self):
     rdf_aff4.AFF4ObjectLabel(name="b/label.42:1", owner="test")
Beispiel #11
0
 def testColonIsAllowed(self):
     rdf_aff4.AFF4ObjectLabel(name="label.42:1", owner="test")
Beispiel #12
0
 def testDotIsAllowed(self):
     rdf_aff4.AFF4ObjectLabel(name="label.42", owner="test")
Beispiel #13
0
 def testAlphanumericCharactersAreAllowed(self):
     rdf_aff4.AFF4ObjectLabel(name="label42", owner="test")
Beispiel #14
0
 def GenerateSample(self, number=0):
     return rdf_aff4.AFF4ObjectLabel(
         name="label%d" % number,
         owner="test",
         timestamp=rdfvalue.RDFDatetime.FromSecondsSinceEpoch(42))