def test_binary(): const = stix2.BinaryConstant("dGhpcyBpcyBhIHRlc3Q=") exp = stix2.EqualityComparisonExpression( "artifact:payload_bin", const, ) assert str(exp) == "artifact:payload_bin = b'dGhpcyBpcyBhIHRlc3Q='"
def visitTerminal(self, node): if node.symbol.type == STIXPatternParser.IntLiteral: return stix2.IntegerConstant(node.getText()) elif node.symbol.type == STIXPatternParser.FloatLiteral: return stix2.FloatConstant(node.getText()) elif node.symbol.type == STIXPatternParser.HexLiteral: return stix2.HexConstant(node.getText()) elif node.symbol.type == STIXPatternParser.BinaryLiteral: return stix2.BinaryConstant(node.getText()) elif node.symbol.type == STIXPatternParser.StringLiteral: return stix2.StringConstant(node.getText().strip('\'')) elif node.symbol.type == STIXPatternParser.BoolLiteral: return stix2.BooleanConstant(node.getText()) elif node.symbol.type == STIXPatternParser.TimestampLiteral: return stix2.TimestampConstant(node.getText()) # TODO: timestamp else: return node
def test_invalid_binary_constant(): with pytest.raises(ValueError): stix2.BinaryConstant('foo')
def test_invalid_binary_constant(): with pytest.raises(ValueError) as excinfo: stix2.BinaryConstant('foo') assert 'must contain a base64' in str(excinfo)