Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into PE-7422-on-boot
Browse files Browse the repository at this point in the history
  • Loading branch information
atticusofsparta committed Jan 23, 2025
2 parents 76e103f + 7c6e10e commit de0dbf2
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 13 deletions.
62 changes: 52 additions & 10 deletions spec/utils_spec.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
-- spec/utils_spec.lua
local utils = require(".common.utils")
local constants = require("src.common.constants")

local testEthAddress = "0xFCAd0B19bB29D4674531d6f115237E16AfCE377c"

Expand Down Expand Up @@ -92,15 +93,56 @@ describe("utils.isValidAOAddress", function()
end)

describe("utils.validateUndername", function()
it("should throw an error for invalid undernames", function()
local invalid, error = pcall(utils.validateUndername, "_invalid_undername_")
assert.is_false(invalid)
assert.is_not_nil(error)
end)

it("should not throw an error for a valid undername", function()
local valid, error = pcall(utils.validateUndername, "valid-undername-123")
assert.is_true(valid)
assert.is_nil(error)
it("should allow valid undernames", function()
local validNames = {
"@",
"a",
"aA",
"Z_",
"z-",
"1",
"1-",
string.rep("a", 61),
string.rep("z", 60) .. "_",
string.rep("0", 60) .. "-",
}

for _, name in ipairs(validNames) do
local success, error = pcall(utils.validateUndername, name)
assert.is_true(success, name .. " should be valid")
assert.is_nil(error, name .. " got an error: " .. tostring(error))
end
end)

it("should not allow invalid undernames", function()
local invalidNames = {
nil,

"",
"_",
"-",
"_a",
"-a",
string.rep("a", 62), -- overlength
"-" .. string.rep("a", 60),
"_" .. string.rep("a", 60),
"@@",
"a@",
".",
"#",
"&",
":",
"a.",
"a#",
"a&",
"a:",
}

for _, name in ipairs(invalidNames) do
local invalid, error = pcall(utils.validateUndername, name)
assert.is_false(invalid, name .. " should be invalid")
assert.is_not_nil(error, "error for " .. name .. " was nil: " .. tostring(error))
assert.equal(constants.UNDERNAME_DOES_NOT_EXIST_MESSAGE, tostring(error))
end
end)
end)
9 changes: 7 additions & 2 deletions src/common/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,14 @@ end
---utils.validateUndername("my-undername")
---```
function utils.validateUndername(name)
--- RULES FOR UNDERNAMES
--- min 1 char
--- max 61 chars
--- no starting dashes or underscores
--- alphanumeric, dashes, underscores OR one '@' sign

local validLength = #name <= constants.MAX_UNDERNAME_LENGTH
local validRegex = string.match(name, "^@$") ~= nil
or string.match(name, "^[a-zA-Z0-9][a-zA-Z0-9_-]*[a-zA-Z0-9]$") ~= nil
local validRegex = string.match(name, "^@$") ~= nil or string.match(name, "^[a-zA-Z0-9]+[a-zA-Z0-9_-]*$") ~= nil
local valid = validLength and validRegex
assert(valid, constants.UNDERNAME_DOES_NOT_EXIST_MESSAGE)
end
Expand Down
12 changes: 12 additions & 0 deletions test/records.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@ describe('aos Records', async () => {
);
}

async function removeRecord(name, mem) {
return handle(
{
Tags: [
{ name: 'Action', value: 'Remove-Record' },
{ name: 'Sub-Domain', value: name },
],
},
mem,
);
}

async function getRecords(mem) {
const res = await handle(
{
Expand Down
1 change: 0 additions & 1 deletion tools/publish-module.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const __dirname = dirname(__filename);

const wasmBinary = fs.readFileSync(
path.join(__dirname, '../dist/aos-ant.wasm'),
'utf-8',
);

// Read the file
Expand Down

0 comments on commit de0dbf2

Please sign in to comment.