Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
scapy
Manage
Activity
Members
Plan
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
CodeLinaro
public-release-test-restored
platform
external
scapy
Commits
d02b7f5b
Commit
d02b7f5b
authored
7 years ago
by
gpotter2
Browse files
Options
Downloads
Patches
Plain Diff
New tests to avoid randomness of coverage
parent
7476e931
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
scapy/layers/inet.py
+4
-1
4 additions, 1 deletion
scapy/layers/inet.py
test/fields.uts
+23
-0
23 additions, 0 deletions
test/fields.uts
test/regression.uts
+35
-0
35 additions, 0 deletions
test/regression.uts
with
62 additions
and
1 deletion
scapy/layers/inet.py
+
4
−
1
View file @
d02b7f5b
...
@@ -226,6 +226,9 @@ TCPOptions = (
...
@@ -226,6 +226,9 @@ TCPOptions = (
25
:
(
"
Mood
"
,
"
!p
"
),
25
:
(
"
Mood
"
,
"
!p
"
),
28
:
(
"
UTO
"
,
"
!H
"
),
28
:
(
"
UTO
"
,
"
!H
"
),
34
:
(
"
TFO
"
,
"
!II
"
),
34
:
(
"
TFO
"
,
"
!II
"
),
# RFC 3692
253
:
(
"
Experiment
"
,
"
!HHHH
"
),
254
:
(
"
Experiment
"
,
"
!HHHH
"
),
},
},
{
"
EOL
"
:
0
,
{
"
EOL
"
:
0
,
"
NOP
"
:
1
,
"
NOP
"
:
1
,
...
@@ -482,7 +485,7 @@ class TCP(Packet):
...
@@ -482,7 +485,7 @@ class TCP(Packet):
ShortField
(
"
window
"
,
8192
),
ShortField
(
"
window
"
,
8192
),
XShortField
(
"
chksum
"
,
None
),
XShortField
(
"
chksum
"
,
None
),
ShortField
(
"
urgptr
"
,
0
),
ShortField
(
"
urgptr
"
,
0
),
TCPOptionsField
(
"
options
"
,
{}
)
]
TCPOptionsField
(
"
options
"
,
[]
)
]
def
post_build
(
self
,
p
,
pay
):
def
post_build
(
self
,
p
,
pay
):
p
+=
pay
p
+=
pay
dataofs
=
self
.
dataofs
dataofs
=
self
.
dataofs
...
...
This diff is collapsed.
Click to expand it.
test/fields.uts
+
23
−
0
View file @
d02b7f5b
...
@@ -319,6 +319,14 @@ assert(Raw in b and b[Raw].load == "123456")
...
@@ -319,6 +319,14 @@ assert(Raw in b and b[Raw].load == "123456")
hexdiff(a,b)
hexdiff(a,b)
assert( str(a) == str(b) )
assert( str(a) == str(b) )
############
############
+ Tests on TCPOptionsField
= Test calls on TCPOptionsField.getfield
assert TCPOptionsField("test", "").getfield(TCP(dataofs=0), "") == ('', [])
############
############
############
############
...
@@ -769,3 +777,18 @@ assert(f.i2repr_one(None, 1) == 'Bar')
...
@@ -769,3 +777,18 @@ assert(f.i2repr_one(None, 1) == 'Bar')
assert(f.i2repr_one(None, 0xff) == '0xff')
assert(f.i2repr_one(None, 0xff) == '0xff')
True
True
############
############
+ DNSStrField tests
= Raise exception - test data
dnsf = DNSStrField("test", "")
assert(dnsf.getfield("", b"\x01\x02\x00") == ("", b"\x02."))
try:
dnsf.getfield("", b"\xff")
assert(False)
except Scapy_Exception:
pass
This diff is collapsed.
Click to expand it.
test/regression.uts
+
35
−
0
View file @
d02b7f5b
...
@@ -5358,6 +5358,33 @@ str(TCP(options=[("UTO", 0xffff)])) == b"\x00\x14\x00\x50\x00\x00\x00\x00\x00\x0
...
@@ -5358,6 +5358,33 @@ str(TCP(options=[("UTO", 0xffff)])) == b"\x00\x14\x00\x50\x00\x00\x00\x00\x00\x0
uto = TCP(b"\x00\x14\x00\x50\x00\x00\x00\x00\x00\x00\x00\x00\x60\x02\x20\x00\x00\x00\x00\x00\x1c\x04\xff\xff")
uto = TCP(b"\x00\x14\x00\x50\x00\x00\x00\x00\x00\x00\x00\x00\x60\x02\x20\x00\x00\x00\x00\x00\x1c\x04\xff\xff")
uto[TCP].options[0][0] == "UTO" and uto[TCP].options[0][1] == 0xffff
uto[TCP].options[0][0] == "UTO" and uto[TCP].options[0][1] == 0xffff
= TCP options: SAck - basic build
str(TCP(options=[(5, "abcdefgh")])) == b"\x00\x14\x00P\x00\x00\x00\x00\x00\x00\x00\x00\x80\x02 \x00\x00\x00\x00\x00\x05\nabcdefgh\x00\x00"
= TCP options: SAck - basic dissection
sack = TCP(b"\x00\x14\x00P\x00\x00\x00\x00\x00\x00\x00\x00\x80\x02 \x00\x00\x00\x00\x00\x05\nabcdefgh\x00\x00")
sack[TCP].options[0][0] == "SAck" and sack[TCP].options[0][1] == (1633837924, 1701209960)
= TCP options: SAckOK - basic build
str(TCP(options=[('SAckOK', '')])) == b"\x00\x14\x00P\x00\x00\x00\x00\x00\x00\x00\x00`\x02 \x00\x00\x00\x00\x00\x04\x02\x00\x00"
= TCP options: SAckOK - basic dissection
sackok = TCP(b"\x00\x14\x00P\x00\x00\x00\x00\x00\x00\x00\x00`\x02 \x00\x00\x00\x00\x00\x04\x02\x00\x00")
sackok[TCP].options[0][0] == "SAckOK" and sackok[TCP].options[0][1] == ''
= TCP options: EOL - basic build
str(TCP(options=[(0, '')])) == b"\x00\x14\x00P\x00\x00\x00\x00\x00\x00\x00\x00`\x02 \x00\x00\x00\x00\x00\x00\x02\x00\x00"
= TCP options: EOL - basic dissection
eol = TCP(b"\x00\x14\x00P\x00\x00\x00\x00\x00\x00\x00\x00`\x02 \x00\x00\x00\x00\x00\x00\x02\x00\x00")
eol[TCP].options[0][0] == "EOL" and eol[TCP].options[0][1] == None
= TCP options: malformed - build
str(TCP(options=[('unknown', '')])) == str(TCP())
= TCP options: malformed - dissection
str(TCP(b"\x00\x14\x00P\x00\x00\x00\x00\x00\x00\x00\x00`\x02 \x00\x00\x00\x00\x00\x03\x00\x00\x00")) == b"\x00\x14\x00P\x00\x00\x00\x00\x00\x00\x00\x00`\x02 \x00\x00\x00\x00\x00\x03\x00\x00\x00"
= IP, TCP & UDP checksums (these tests highly depend on default values)
= IP, TCP & UDP checksums (these tests highly depend on default values)
pkt = IP() / TCP()
pkt = IP() / TCP()
bpkt = IP(str(pkt))
bpkt = IP(str(pkt))
...
@@ -8164,6 +8191,7 @@ assert(param1.random != param2.random)
...
@@ -8164,6 +8191,7 @@ assert(param1.random != param2.random)
= BOOTP - misc
= BOOTP - misc
BOOTP().answers(BOOTP()) == True
BOOTP().answers(BOOTP()) == True
BOOTP().hashret() == b"\x00\x00\x00\x00"
import random
import random
random.seed(0x2807)
random.seed(0x2807)
...
@@ -8174,6 +8202,13 @@ dof = DHCPOptionsField("options", value)
...
@@ -8174,6 +8202,13 @@ dof = DHCPOptionsField("options", value)
dof.i2repr("", value) == '[hostname scapy]'
dof.i2repr("", value) == '[hostname scapy]'
dof.i2m("", value) == b'\x0cscapy'
dof.i2m("", value) == b'\x0cscapy'
unknown_value_end = b"\xfe" + b"\xff"*257
udof = DHCPOptionsField("options", unknown_value_end)
udof.m2i("", unknown_value_end) == [(254, '\xff'*255), 'end']
unknown_value_pad = b"\xfe" + b"\xff"*256 + b"\x00"
udof = DHCPOptionsField("options", unknown_value_pad)
udof.m2i("", unknown_value_pad) == [(254, '\xff'*255), 'pad']
= DHCP - build
= DHCP - build
s = str(IP()/UDP()/BOOTP(chaddr="00:01:02:03:04:05")/DHCP(options=[("message-type","discover"),"end"]))
s = str(IP()/UDP()/BOOTP(chaddr="00:01:02:03:04:05")/DHCP(options=[("message-type","discover"),"end"]))
...
...
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