fix/2444 TOTP input validation for correct otpauth uri generation (#2621)

This commit is contained in:
alleria173 2026-07-03 11:23:06 +01:00 committed by GitHub
parent 179eb9a379
commit c51e21a242
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 89 additions and 4 deletions

View File

@ -26,22 +26,30 @@ class GenerateTOTP extends Operation {
{ {
"name": "Name", "name": "Name",
"type": "string", "type": "string",
"value": "" "value": "Account",
"allowEmpty": false
}, },
{ {
"name": "Code length", "name": "Code length",
"type": "number", "type": "number",
"value": 6 "value": 6,
"min": 6,
"max": 8,
"integer": true
}, },
{ {
"name": "Epoch offset (T0)", "name": "Epoch offset (T0)",
"type": "number", "type": "number",
"value": 0 "value": 0,
"min": 0,
"integer": true
}, },
{ {
"name": "Interval (T1)", "name": "Interval (T1)",
"type": "number", "type": "number",
"value": 30 "value": 30,
"min": 1,
"integer": true
} }
]; ];
} }

View File

@ -86,4 +86,81 @@ TestRegister.addTests([
}, },
], ],
}, },
{
name: "Generate TOTP",
input: "JBSWY3DPEHPK3PXP",
expectedMatch: /^URI: otpauth:\/\/totp\/Account\?secret=JBSWY3DPEHPK3PXP&algorithm=SHA1&digits=6&period=30\n\nPassword: \d{6}$/,
recipeConfig: [
{
op: "Generate TOTP",
args: ["Account", 6, 0, 30], // [Name, Code length, Epoch offset (T0), Interval (T1)]
},
],
},
{
name: "Generate TOTP - empty name rejected",
input: "JBSWY3DPEHPK3PXP",
expectedOutput: "Name cannot be empty.",
recipeConfig: [
{
op: "Generate TOTP",
args: ["", 6, 0, 30],
},
],
},
{
name: "Generate TOTP - code length below minimum rejected",
input: "JBSWY3DPEHPK3PXP",
expectedOutput: "Code length must be greater than or equal to 6.",
recipeConfig: [
{
op: "Generate TOTP",
args: ["Account", -6, 0, 30],
},
],
},
{
name: "Generate TOTP - code length above maximum rejected",
input: "JBSWY3DPEHPK3PXP",
expectedOutput: "Code length must be less than or equal to 8.",
recipeConfig: [
{
op: "Generate TOTP",
args: ["Account", 9, 0, 30],
},
],
},
{
name: "Generate TOTP - non-integer code length rejected",
input: "JBSWY3DPEHPK3PXP",
expectedOutput: "Code length must be an integer.",
recipeConfig: [
{
op: "Generate TOTP",
args: ["Account", 6.5, 0, 30],
},
],
},
{
name: "Generate TOTP - negative interval rejected",
input: "JBSWY3DPEHPK3PXP",
expectedOutput: "Interval (T1) must be greater than or equal to 1.",
recipeConfig: [
{
op: "Generate TOTP",
args: ["Account", 6, 0, -1],
},
],
},
{
name: "Generate TOTP - negative epoch offset rejected",
input: "JBSWY3DPEHPK3PXP",
expectedOutput: "Epoch offset (T0) must be greater than or equal to 0.",
recipeConfig: [
{
op: "Generate TOTP",
args: ["Account", 6, -1, 30],
},
],
},
]); ]);