Add support for CPE digest authentication
This commit is contained in:
1 parent
f21ce3053a
commit
344ed3fdee
5 files changed
+228
-86
No files matched your search
@@ -0,0 +1,49 @@
|
||||
import ava from "ava";
|
||||
import { randomBytes } from "crypto";
|
||||
import * as auth from "../lib/auth";
|
||||
|
||||
ava("digest", t => {
|
||||
const username = "test";
|
||||
const password = "test";
|
||||
const uri = "/";
|
||||
const method = "POST";
|
||||
const realm = "GeniceACS";
|
||||
const nonce = randomBytes(16).toString("hex");
|
||||
const body = randomBytes(128).toString();
|
||||
|
||||
const challenges = [
|
||||
`Digest realm="${realm}",nonce="${nonce}"`,
|
||||
`Digest realm="${realm}",nonce="${nonce}",qop="auth"`,
|
||||
`Digest realm="${realm}",nonce="${nonce}",qop="auth-int"`
|
||||
];
|
||||
|
||||
t.plan(challenges.length);
|
||||
|
||||
for (const challenge of challenges) {
|
||||
const wwwAuthHeader = auth.parseWwwAuthenticateHeader(challenge);
|
||||
const solution = auth.solveDigest(
|
||||
username,
|
||||
password,
|
||||
uri,
|
||||
method,
|
||||
body,
|
||||
wwwAuthHeader
|
||||
);
|
||||
const authHeader = auth.parseAuthorizationHeader(solution);
|
||||
t.is(
|
||||
authHeader["response"],
|
||||
auth.digest(
|
||||
username,
|
||||
realm,
|
||||
password,
|
||||
nonce,
|
||||
method,
|
||||
uri,
|
||||
authHeader["qop"],
|
||||
body,
|
||||
authHeader["cnonce"],
|
||||
authHeader["nc"]
|
||||
)
|
||||
);
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user