Skip to content

Commit e74f5f5

Browse files
committed
1 parent c6483fa commit e74f5f5

2 files changed

Lines changed: 95 additions & 0 deletions

File tree

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
describe("PoEAPI auth", function()
2+
local originalLaunchSubScript
3+
local originalDownloadPage
4+
local originalSubScripts
5+
6+
before_each(function()
7+
originalLaunchSubScript = _G.LaunchSubScript
8+
originalDownloadPage = launch.DownloadPage
9+
originalSubScripts = launch.subScripts
10+
launch.subScripts = { }
11+
end)
12+
13+
after_each(function()
14+
_G.LaunchSubScript = originalLaunchSubScript
15+
launch.DownloadPage = originalDownloadPage
16+
launch.subScripts = originalSubScripts
17+
end)
18+
19+
it("passes token exchange errors to the auth callback #auth", function()
20+
local authState
21+
_G.LaunchSubScript = function(_, _, _, authUrl)
22+
authState = authUrl:match("state=([^&]+)")
23+
return 123
24+
end
25+
launch.DownloadPage = function(_, url, callback)
26+
assert.are.equals("https://www.pathofexile.com/oauth/token", url)
27+
callback(nil, "SSL connect error")
28+
end
29+
30+
local api = new("PoEAPI")
31+
local callbackArgs
32+
api:FetchAuthToken(function(response, errMsg, updateSettings)
33+
callbackArgs = {
34+
response = response,
35+
errMsg = errMsg,
36+
updateSettings = updateSettings,
37+
}
38+
end)
39+
40+
assert.is_not_nil(authState)
41+
assert.is_not_nil(launch.subScripts[123])
42+
launch.subScripts[123].callback("auth-code", nil, authState, 12345)
43+
44+
assert.is_nil(callbackArgs.response)
45+
assert.are.equals("SSL connect error", callbackArgs.errMsg)
46+
assert.True(callbackArgs.updateSettings)
47+
assert.is_nil(api.authToken)
48+
end)
49+
50+
it("reports OAuth state mismatches without exchanging a token", function()
51+
_G.LaunchSubScript = function()
52+
return 123
53+
end
54+
launch.DownloadPage = function()
55+
error("token exchange should not run for mismatched OAuth state")
56+
end
57+
58+
local api = new("PoEAPI")
59+
local callbackArgs
60+
api:FetchAuthToken(function(response, errMsg, updateSettings)
61+
callbackArgs = {
62+
response = response,
63+
errMsg = errMsg,
64+
updateSettings = updateSettings,
65+
}
66+
end)
67+
68+
assert.is_not_nil(launch.subScripts[123])
69+
launch.subScripts[123].callback("auth-code", nil, "wrong-state", 12345)
70+
71+
assert.is_nil(callbackArgs.response)
72+
assert.are.equals("OAuth state mismatch", callbackArgs.errMsg)
73+
assert.True(callbackArgs.updateSettings)
74+
assert.is_nil(api.authToken)
75+
end)
76+
end)

src/Classes/ImportTab.lua.rej

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
diff a/src/Classes/ImportTab.lua b/src/Classes/ImportTab.lua (rejected hunks)
2+
@@ -49,7 +49,7 @@ local ImportTabClass = newClass("ImportTab", "ControlHost", "Control", function(
3+
4+
-- Stage: Authenticate
5+
self.controls.authenticateButton = new("ButtonControl", {"TOPLEFT",self.controls.characterImportAnchor,"TOPLEFT"}, {0, 0, 200, 16}, "^7Authorize with Path of Exile", function()
6+
- self.api:FetchAuthToken(function()
7+
+ self.api:FetchAuthToken(function(_, errMsg)
8+
if self.api.authToken then
9+
self.charImportMode = "GETACCOUNTNAME"
10+
self.charImportStatus = "Authenticated"
11+
@@ -59,6 +59,8 @@ local ImportTabClass = newClass("ImportTab", "ControlHost", "Control", function(
12+
main.tokenExpiry = self.api.tokenExpiry
13+
main:SaveSettings()
14+
self:DownloadCharacterList()
15+
+ elseif errMsg and errMsg ~= self.api.ERROR_NO_AUTH then
16+
+ self.charImportStatus = colorCodes.NEGATIVE.."Authentication failed: "..errMsg
17+
else
18+
self.charImportStatus = colorCodes.WARNING.."Not authenticated"
19+
end

0 commit comments

Comments
 (0)