-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from kytos-ng/fix/get_cookie_overflow
fix: 2022.3.1 release: coloring `get_cookie` can generate an cookie that overflows 8 bytes
- Loading branch information
Showing
6 changed files
with
68 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
"""Test utils.py.""" | ||
import pytest | ||
|
||
|
||
from napps.amlight.coloring.utils import make_unicast_local_mac | ||
|
||
|
||
def test_make_unicast_local_mac_valid() -> None: | ||
"""test make_unicast_local_mac.""" | ||
mac = "31:94:06:ee:ee:ee" | ||
assert make_unicast_local_mac(mac) == "3e:94:06:ee:ee:ee" | ||
|
||
|
||
@pytest.mark.parametrize("mac", ["31:94:06:ee:ee:eea", "a", ""]) | ||
def test_make_unicast_local_mac_errors(mac) -> None: | ||
"""test make_unicast_local_mac.""" | ||
with pytest.raises(ValueError): | ||
assert make_unicast_local_mac(mac) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
"""Utilities.""" | ||
import re | ||
|
||
MAC_ADDR = re.compile("([0-9A-Fa-f]{2}[-:]){5}[0-9A-Fa-f]{2}$") | ||
|
||
|
||
def make_unicast_local_mac(mac: str) -> str: | ||
""" | ||
The first two bits (b0, b1) of the most significant MAC address byte is for | ||
its uniquiness and wether its locally administered or not. This functions | ||
ensures it's a unicast (b0 -> 0) and locally administered (b1 -> 1). | ||
""" | ||
if not re.search(MAC_ADDR, mac): | ||
msg = "Invalid mac '{mac}': expected this regex format: {MAC_ADDR}" | ||
raise ValueError(msg) | ||
mac = mac.lower() | ||
return mac[:1] + "e" + mac[2:] |