Skip to content

Commit 4efb946

Browse files
committed
fix: correct mock server counting impl
1 parent 5fe6b91 commit 4efb946

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

test/authserver.jl

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@ const PORT = 8888
99
const TOKEN = Ref(Dict())
1010
const MODE = Ref(CLASSIC_MODE)
1111

12-
const TOKEN_COUNTER = Ref(0)
13-
function id_token()
14-
return string(TOKEN_COUNTER[] += 1)
12+
const REQUEST_SET = Set()
13+
# this counts the number of distinct authentication requests made against the server
14+
function id_token(key)
15+
push!(REQUEST_SET, key)
16+
token = length(REQUEST_SET)
17+
return string(token)
1518
end
1619

1720
challenge_response_map = Dict()
@@ -46,8 +49,8 @@ function response_handler(req)
4649
TOKEN[] = Dict(
4750
"user_name" => "firstname lastname",
4851
"user_email" => "[email protected]",
49-
"id_token" => "full-" * id_token(),
50-
"access_token" => "full-" * id_token(),
52+
"id_token" => "full-" * id_token(response),
53+
"access_token" => "full-" * id_token(response),
5154
"refresh_token" => refresh_token,
5255
"refresh_url" => "http://localhost:$(PORT)/auth/renew/token.toml/v2/",
5356
"expires_in" => EXPIRY,
@@ -93,8 +96,8 @@ function renew_handler(req)
9396

9497
TOKEN[]["refresh_token"] = Random.randstring(10)
9598
TOKEN[]["expires_at"] = ceil(Int, time() + EXPIRY)
96-
TOKEN[]["id_token"] = "refresh-" * id_token()
97-
TOKEN[]["access_token"] = "refresh-" * id_token()
99+
TOKEN[]["id_token"] = "refresh-" * id_token(auth)
100+
TOKEN[]["access_token"] = "refresh-" * id_token(auth)
98101

99102
return HTTP.Response(200, sprint(TOML.print, TOKEN[]))
100103
end
@@ -171,11 +174,11 @@ function auth_device(req)
171174
end
172175
authenticated[device_code] = true
173176
refresh_token = Random.randstring(10)
174-
TOKEN[]["access_token"] = "device-$(id_token())"
177+
TOKEN[]["access_token"] = "device-$(id_token(user_code))"
175178
TOKEN[]["token_type"] = "bearer"
176179
TOKEN[]["expires_in"] = EXPIRY
177180
TOKEN[]["refresh_token"] = refresh_token
178-
TOKEN[]["id_token"] = "device-$(id_token())"
181+
TOKEN[]["id_token"] = "device-$(id_token(user_code))"
179182
return HTTP.Response(200)
180183
end
181184

0 commit comments

Comments
 (0)