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)))
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")
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")
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)
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")
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)
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])
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"), [])
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)))
def testForwardSlashIsAllowed(self): rdf_aff4.AFF4ObjectLabel(name="b/label.42:1", owner="test")
def testColonIsAllowed(self): rdf_aff4.AFF4ObjectLabel(name="label.42:1", owner="test")
def testDotIsAllowed(self): rdf_aff4.AFF4ObjectLabel(name="label.42", owner="test")
def testAlphanumericCharactersAreAllowed(self): rdf_aff4.AFF4ObjectLabel(name="label42", owner="test")
def GenerateSample(self, number=0): return rdf_aff4.AFF4ObjectLabel( name="label%d" % number, owner="test", timestamp=rdfvalue.RDFDatetime.FromSecondsSinceEpoch(42))