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

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

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

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

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

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

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

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

        labels_list.AddLabel(
            aff4_rdfvalues.AFF4ObjectLabel(name="foo", owner="test"))
        self.assertEqual(len(labels_list.labels), 1)
Beispiel #5
0
    def testAddLabelAddsLabelWithSameNameButDifferentOwner(self):
        labels_list = aff4_rdfvalues.AFF4ObjectLabelsList()

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

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

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

        self.assertEqual(utils.SmartStr(labels_list), "bar,foo")
Beispiel #7
0
    def GenerateSample(self, number=0):
        label1 = aff4_rdfvalues.AFF4ObjectLabel(
            name="foo_%d" % number,
            owner="test",
            timestamp=rdfvalue.RDFDatetime.FromSecondsSinceEpoch(42))

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

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

        labels_list.AddLabel(
            aff4_rdfvalues.AFF4ObjectLabel(name="foo", owner="test"))
        labels_list.AddLabel(
            aff4_rdfvalues.AFF4ObjectLabel(name="foo2", owner="test2"))
        labels_list.AddLabel(
            aff4_rdfvalues.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 = aff4_rdfvalues.AFF4ObjectLabelsList()

        labels_list.AddLabel(
            aff4_rdfvalues.AFF4ObjectLabel(name="ein", owner="GRR"))
        labels_list.AddLabel(
            aff4_rdfvalues.AFF4ObjectLabel(name="zwei", owner="test"))
        self.assertFalse(
            re.match(
                aff4_rdfvalues.AFF4ObjectLabelsList.
                RegexForStringifiedValueMatch("e"), str(labels_list)))
        self.assertFalse(
            re.match(
                aff4_rdfvalues.AFF4ObjectLabelsList.
                RegexForStringifiedValueMatch("in"), str(labels_list)))
        self.assertFalse(
            re.match(
                aff4_rdfvalues.AFF4ObjectLabelsList.
                RegexForStringifiedValueMatch("a.zwer"), str(labels_list)))
        self.assertFalse(
            re.match(
                aff4_rdfvalues.AFF4ObjectLabelsList.
                RegexForStringifiedValueMatch("ein."), str(labels_list)))