Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yara-python
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
fact-depend
yara-python
Commits
e58af70e
Unverified
Commit
e58af70e
authored
Oct 05, 2021
by
Steven
Committed by
GitHub
Oct 06, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add namespace, rule, and string to warning callback test (#182)
parent
17979fe3
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
9 deletions
+17
-9
tests.py
tests.py
+17
-9
No files found.
tests.py
View file @
e58af70e
#!/usr/local/bin/python
# -*- coding: utf-8 -*-
#
# Copyright (c) 2007-20
14
. The YARA Authors. All Rights Reserved.
# Copyright (c) 2007-20
21
. The YARA Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
...
...
@@ -75,7 +75,6 @@ ab000000000000001a0000000000000000000000000000000100000000000000\
# The 3 possible outcomes for each pattern
[
SUCCEED
,
FAIL
,
SYNTAX_ERROR
]
=
range
(
3
)
RE_TESTS
=
[
# RE, string, expected result, expected matching
...
...
@@ -268,8 +267,9 @@ RE_TESTS = [
def
warnings_callback
(
warning_type
,
message
):
global
warnings_callback_called
global
warnings_callback_called
,
warnings_callback_message
warnings_callback_called
=
warning_type
warnings_callback_message
=
message
class
TestYara
(
unittest
.
TestCase
):
...
...
@@ -876,11 +876,11 @@ class TestYara(unittest.TestCase):
if
sys
.
version_info
[
0
]
>=
3
:
self
.
assertTrue
(
yara
.
compile
(
source
=
"rule test { condition: true}"
,
externals
=
{
'foo'
:
u'
\u6765\u6613\u7f51\u7edc\u79d1
'
}))
externals
=
{
'foo'
:
u'
\u6765\u6613\u7f51\u7edc\u79d1
'
}))
else
:
self
.
assertRaises
(
UnicodeEncodeError
,
yara
.
compile
,
source
=
"rule test { condition: true}"
,
externals
=
{
'foo'
:
u'
\u6765\u6613\u7f51\u7edc\u79d1
'
})
externals
=
{
'foo'
:
u'
\u6765\u6613\u7f51\u7edc\u79d1
'
})
def
testCallbackAll
(
self
):
global
rule_data
...
...
@@ -891,7 +891,6 @@ class TestYara(unittest.TestCase):
rule_data
.
append
(
data
)
return
yara
.
CALLBACK_CONTINUE
r
=
yara
.
compile
(
source
=
'rule t { condition: true } rule f { condition: false }'
)
r
.
match
(
data
=
'dummy'
,
callback
=
callback
,
which_callbacks
=
yara
.
CALLBACK_ALL
)
...
...
@@ -1099,14 +1098,23 @@ class TestYara(unittest.TestCase):
self
.
assertTrue
(
r
.
match
(
data
=
data
))
def
testWarningCallback
(
self
):
global
warnings_callback_called
global
warnings_callback_called
,
warnings_callback_message
warnings_callback_called
=
False
r
=
yara
.
compile
(
source
=
'rule x { strings: $x = "X" condition: $x }'
)
warnings_callback_message
=
None
r
=
yara
.
compile
(
sources
=
{
'ns1'
:
'rule x { strings: $x = "X" condition: $x }'
})
data
=
memoryview
(
b
"X"
*
1000099
)
r
.
match
(
data
=
data
,
warnings_callback
=
warnings_callback
)
self
.
assertTrue
(
warnings_callback_called
,
yara
.
CALLBACK_TOO_MANY_MATCHES
)
self
.
assertTrue
(
warnings_callback_called
==
yara
.
CALLBACK_TOO_MANY_MATCHES
)
self
.
assertTrue
(
warnings_callback_message
==
(
"ns1"
,
"x"
,
"$x"
))
self
.
assertTrue
(
warnings_callback_message
.
namespace
==
"ns1"
)
self
.
assertTrue
(
warnings_callback_message
.
rule
==
"x"
)
self
.
assertTrue
(
warnings_callback_message
.
string
==
"$x"
)
if
__name__
==
"__main__"
:
unittest
.
main
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment