@@ -119,4 +119,42 @@ describe("builtin request hooks", function()
119119 assert .same ({ " application/json" }, req .headers [" content-type" ])
120120 end )
121121 end )
122+ --- @return rest.Request
123+ local function sample_request (opts )
124+ return vim .tbl_deep_extend (" keep" , opts , {
125+ method = " GET" ,
126+ url = " https://example.com" ,
127+ headers = {},
128+ cookies = {},
129+ handlers = {},
130+ })
131+ end
132+ describe (" interpret_basic_auth" , function ()
133+ it (" with valid vscode style token" , function ()
134+ local req = sample_request ({
135+ headers = {
136+ [" authorization" ] = { " Basic username:password" },
137+ },
138+ })
139+ _G .rest_request = req
140+ vim .api .nvim_exec_autocmds (" User" , {
141+ pattern = { " RestRequest" , " RestRequestPre" },
142+ })
143+ _G .rest_request = nil
144+ assert .same ({ " Basic dXNlcm5hbWU6cGFzc3dvcmQ=" }, req .headers [" authorization" ])
145+ end )
146+ it (" with valid intellij style token" , function ()
147+ local req = sample_request ({
148+ headers = {
149+ [" authorization" ] = { " Basic username password" },
150+ },
151+ })
152+ _G .rest_request = req
153+ vim .api .nvim_exec_autocmds (" User" , {
154+ pattern = { " RestRequest" , " RestRequestPre" },
155+ })
156+ _G .rest_request = nil
157+ assert .same ({ " Basic dXNlcm5hbWU6cGFzc3dvcmQ=" }, req .headers [" authorization" ])
158+ end )
159+ end )
122160end )
0 commit comments