diff options
author | Kim Alvefur <zash@zash.se> | 2023-05-26 20:45:10 +0200 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2023-05-26 20:45:10 +0200 |
commit | d947a5273cbbc2ec1d18cc6b4b08b49a95f0e7ef (patch) | |
tree | 889a63794054a7805eb55e97c9009ed4d97a8307 /spec | |
parent | 8f7b31f616545f788723f29306919551e55cbb5c (diff) | |
download | prosody-d947a5273cbbc2ec1d18cc6b4b08b49a95f0e7ef.tar.gz prosody-d947a5273cbbc2ec1d18cc6b4b08b49a95f0e7ef.zip |
util.sasl: Add basic tests for OAUTHBEARER
Diffstat (limited to 'spec')
-rw-r--r-- | spec/util_sasl_spec.lua | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/spec/util_sasl_spec.lua b/spec/util_sasl_spec.lua index 368291b3..67b60758 100644 --- a/spec/util_sasl_spec.lua +++ b/spec/util_sasl_spec.lua @@ -39,5 +39,37 @@ describe("util.sasl", function () -- TODO SCRAM end); + + describe("oauthbearer profile", function() + local profile = { + oauthbearer = function(_, token, _realm, _authzid) + if token == "example-bearer-token" then + return "user", true, {}; + else + return nil, nil, {} + end + end; + } + + it("works with OAUTHBEARER", function() + local bearer = sasl.new("sasl.test", profile); + + assert.truthy(bearer:select("OAUTHBEARER")); + assert.equals("success", bearer:process("n,,\1auth=Bearer example-bearer-token\1\1")); + assert.equals("user", bearer.username); + end) + + + it("returns extras with OAUTHBEARER", function() + local bearer = sasl.new("sasl.test", profile); + + assert.truthy(bearer:select("OAUTHBEARER")); + local status, extra = bearer:process("n,,\1auth=Bearer unknown\1\1"); + assert.equals("challenge", status); + assert.equals("{\"status\":\"invalid_token\"}", extra); + assert.equals("failure", bearer:process("\1")); + end) + + end) end); |