diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /comm/mail/components/addrbook/test/browser/data/token.sjs | |
parent | Initial commit. (diff) | |
download | thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'comm/mail/components/addrbook/test/browser/data/token.sjs')
-rw-r--r-- | comm/mail/components/addrbook/test/browser/data/token.sjs | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/comm/mail/components/addrbook/test/browser/data/token.sjs b/comm/mail/components/addrbook/test/browser/data/token.sjs new file mode 100644 index 0000000000..e070f8d55f --- /dev/null +++ b/comm/mail/components/addrbook/test/browser/data/token.sjs @@ -0,0 +1,36 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Serves as the token endpoint for OAuth2 testing. + +/* eslint-disable-next-line mozilla/reject-importGlobalProperties */ +Cu.importGlobalProperties(["URLSearchParams"]); + +function handleRequest(request, response) { + let stream = Cc["@mozilla.org/binaryinputstream;1"].createInstance( + Ci.nsIBinaryInputStream + ); + stream.setInputStream(request.bodyInputStream); + + let input = stream.readBytes(request.bodyInputStream.available()); + let params = new URLSearchParams(input); + + response.setHeader("Content-Type", "application/json", false); + + if (params.get("refresh_token") == "expired_token") { + response.setStatusLine("1.1", 400, "Bad Request"); + response.write(JSON.stringify({ error: "invalid_grant" })); + return; + } + + let data = { access_token: "bobs_access_token" }; + + if (params.get("code") == "success") { + // Authorisation just happened, set a different access token so the test + // can detect it, and provide a refresh token. + data.access_token = "new_access_token"; + data.refresh_token = "new_refresh_token"; + } + + response.write(JSON.stringify(data)); +} |