Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Mentat Test 3
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
713
Mentat
Mentat Test 3
Commits
e8009064
Commit
e8009064
authored
4 years ago
by
Rajmund Hruška
Browse files
Options
Downloads
Patches
Plain Diff
Add unit test for node names. (Redmine issue: #6497)
parent
2032b53d
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/mentat/idea/test_sqldb.py
+86
-3
86 additions, 3 deletions
lib/mentat/idea/test_sqldb.py
with
86 additions
and
3 deletions
lib/mentat/idea/test_sqldb.py
+
86
−
3
View file @
e8009064
...
...
@@ -37,7 +37,7 @@ class TestMentatIdeaJSON(unittest.TestCase):
#
verbose
=
False
idea_raw
=
{
idea_raw
_1
=
{
'
Format
'
:
'
IDEA0
'
,
'
ID
'
:
'
4390fc3f-c753-4a3e-bc83-1b44f24baf75
'
,
'
CreateTime
'
:
'
2012-11-03T10:00:02Z
'
,
...
...
@@ -114,6 +114,66 @@ class TestMentatIdeaJSON(unittest.TestCase):
}
}
idea_raw_2
=
{
'
Format
'
:
'
IDEA0
'
,
'
ID
'
:
'
4390fc3f-c753-4a3e-bc83-1b44f24baf76
'
,
'
DetectTime
'
:
'
2012-11-03T10:00:07Z
'
,
'
Category
'
:
[
'
Fraud.Phishing
'
,
'
Test
'
],
'
Node
'
:
[
{
'
Name
'
:
'
org.example.kippo_honey
'
,
'
Realm
'
:
'
cesnet.cz
'
,
'
Type
'
:
[
'
Protocol
'
,
'
Honeypot
'
],
'
SW
'
:
[
'
Kippo
'
],
'
AggrWin
'
:
'
00:05:00
'
},
{
'
Name
'
:
'
org.example.kippo_honey2
'
,
'
Realm
'
:
'
cesnet.cz
'
,
'
Type
'
:
[
'
Protocol
'
,
'
Honeypot
'
],
'
SW
'
:
[
'
Kippo
'
],
'
AggrWin
'
:
'
00:05:00
'
},
]
}
idea_raw_3
=
{
'
Format
'
:
'
IDEA0
'
,
'
ID
'
:
'
4390fc3f-c753-4a3e-bc83-1b44f24baf76
'
,
'
DetectTime
'
:
'
2012-11-03T10:00:07Z
'
,
'
Category
'
:
[
'
Fraud.Phishing
'
,
'
Test
'
],
'
Node
'
:
[
{
'
Name
'
:
'
org.example.kippo_honey
'
,
'
Realm
'
:
'
cesnet.cz
'
,
'
Type
'
:
[
'
Protocol
'
,
'
Honeypot
'
],
'
SW
'
:
[
'
Kippo
'
],
'
AggrWin
'
:
'
00:05:00
'
},
{
'
Type
'
:
[
'
External
'
]
}
]
}
idea_raw_4
=
{
'
Format
'
:
'
IDEA0
'
,
'
ID
'
:
'
4390fc3f-c753-4a3e-bc83-1b44f24baf77
'
,
'
DetectTime
'
:
'
2012-11-03T10:00:07Z
'
,
'
Category
'
:
[
'
Fraud.Phishing
'
,
'
Test
'
],
'
Node
'
:
[
{
'
Realm
'
:
'
cesnet.cz
'
,
'
Type
'
:
[
'
Protocol
'
,
'
Honeypot
'
],
'
SW
'
:
[
'
Kippo
'
],
'
AggrWin
'
:
'
00:05:00
'
},
{
'
Type
'
:
[
'
External
'
]
}
]
}
def
test_01_conv_internal
(
self
):
"""
Perform basic parsing and conversion tests from ``menat.idea.internal.Idea`` class
...
...
@@ -125,11 +185,11 @@ class TestMentatIdeaJSON(unittest.TestCase):
#
# Test conversions of raw JSON IDEA into 'mentat.idea.internal.Idea'.
#
idea_internal
=
mentat
.
idea
.
internal
.
Idea
(
self
.
idea_raw
)
idea_internal
=
mentat
.
idea
.
internal
.
Idea
(
self
.
idea_raw
_1
)
if
self
.
verbose
:
print
(
"'
mentat.idea.internal.Idea
'
out of raw JSON IDEA:
"
)
print
(
json
.
dumps
(
idea_internal
,
indent
=
4
,
sort_keys
=
True
,
default
=
idea_internal
.
json_default
))
orig
=
json
.
dumps
(
self
.
idea_raw
,
indent
=
4
,
sort_keys
=
True
)
orig
=
json
.
dumps
(
self
.
idea_raw
_1
,
indent
=
4
,
sort_keys
=
True
)
new
=
json
.
dumps
(
idea_internal
,
indent
=
4
,
sort_keys
=
True
,
default
=
idea_internal
.
json_default
)
self
.
assertEqual
(
orig
,
new
,
"
\n
"
.
join
([
l
for
l
in
difflib
.
context_diff
(
orig
.
split
(
"
\n
"
),
new
.
split
(
"
\n
"
))]))
...
...
@@ -176,6 +236,29 @@ class TestMentatIdeaJSON(unittest.TestCase):
self
.
assertEqual
(
idea_sqldb
.
cesnet_eventseverity
,
'
low
'
)
self
.
assertEqual
(
idea_sqldb
.
cesnet_inspectionerrors
,
[
'
Demonstration error - first
'
,
'
Demonstration error - second
'
])
def
test_02_missing_node_names
(
self
):
"""
Perform test of presence of node names in the event.
"""
# Only one node
idea_internal
=
mentat
.
idea
.
internal
.
Idea
(
self
.
idea_raw_1
)
idea_sqldb
=
mentat
.
idea
.
sqldb
.
Idea
(
idea_internal
)
self
.
assertEqual
(
idea_sqldb
.
node_name
,
[
'
org.example.kippo_honey
'
])
# Two nodes with two names
idea_internal
=
mentat
.
idea
.
internal
.
Idea
(
self
.
idea_raw_2
)
idea_sqldb
=
mentat
.
idea
.
sqldb
.
Idea
(
idea_internal
)
self
.
assertEqual
(
idea_sqldb
.
node_name
,
[
'
org.example.kippo_honey
'
,
'
org.example.kippo_honey2
'
])
# Two nodes but only one of them has a name
idea_internal
=
mentat
.
idea
.
internal
.
Idea
(
self
.
idea_raw_3
)
idea_sqldb
=
mentat
.
idea
.
sqldb
.
Idea
(
idea_internal
)
self
.
assertEqual
(
idea_sqldb
.
node_name
,
[
'
org.example.kippo_honey
'
])
# Two nodes but there is no name
idea_internal
=
mentat
.
idea
.
internal
.
Idea
(
self
.
idea_raw_4
)
with
self
.
assertRaisesRegexp
(
KeyError
,
"
Missing Node name
"
):
idea_sqldb
=
mentat
.
idea
.
sqldb
.
Idea
(
idea_internal
)
#-------------------------------------------------------------------------------
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment