Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Metabase
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Engineering Digital Service
Metabase
Commits
6d1a1373
Commit
6d1a1373
authored
8 years ago
by
Cam Saül
Browse files
Options
Downloads
Patches
Plain Diff
Add some debugging logging for random test failures
parent
7d980617
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/metabase/middleware.clj
+34
-17
34 additions, 17 deletions
src/metabase/middleware.clj
test/metabase/http_client.clj
+1
-0
1 addition, 0 deletions
test/metabase/http_client.clj
test/metabase/permissions_collection_test.clj
+1
-1
1 addition, 1 deletion
test/metabase/permissions_collection_test.clj
with
36 additions
and
18 deletions
src/metabase/middleware.clj
+
34
−
17
View file @
6d1a1373
...
...
@@ -53,27 +53,44 @@
(
assoc
request
:metabase-session-id
session-id
)
request
))))
(
defn-
add-current-user-id
[{
:keys
[
metabase-session-id
]
:as
request
}]
(
or
(
when
(
and
metabase-session-id
((
resolve
'metabase.core/initialized?
)))
(
when-let
[
session
(
db/select-one
[
Session
:created_at
:user_id
(
db/qualify
User
:is_superuser
)]
(
db/join
[
Session
:user_id
]
[
User
:id
])
(
db/qualify
User
:is_active
)
true
(
db/qualify
Session
:id
)
metabase-session-id
)]
(
let
[
session-age-ms
(
-
(
System/currentTimeMillis
)
(
or
(
when-let
[
^
java.util.Date
created-at
(
:created_at
session
)]
(
.getTime
created-at
))
0
))]
;; If the session exists and is not expired (max-session-age > session-age) then validation is good
(
when
(
and
session
(
>
(
config/config-int
:max-session-age
)
(
quot
session-age-ms
60000
)))
(
assoc
request
:metabase-user-id
(
:user_id
session
)
:is-superuser?
(
:is_superuser
session
))))))
request
))
(
defn-
session-with-id
"Fetch a session with SESSION-ID, and include the User ID and superuser status associated with it."
[
session-id
]
(
db/select-one
[
Session
:created_at
:user_id
(
db/qualify
User
:is_superuser
)]
(
db/join
[
Session
:user_id
]
[
User
:id
])
(
db/qualify
User
:is_active
)
true
(
db/qualify
Session
:id
)
session-id
))
(
defn-
session-age-ms
[
session
]
(
-
(
System/currentTimeMillis
)
(
or
(
when-let
[
^
java.util.Date
created-at
(
:created_at
session
)]
(
.getTime
created-at
))
0
)))
(
defn-
session-age-minutes
[
session
]
(
quot
(
session-age-ms
session
)
60000
))
(
defn-
session-expired?
[
session
]
(
>
(
session-age-minutes
session
)
(
config/config-int
:max-session-age
)))
(
defn-
current-user-info-for-session
"Return User ID and superuser status for Session with SESSION-ID if it is valid and not expired."
[
session-id
]
(
when
(
and
session-id
((
resolve
'metabase.core/initialized?
)))
(
when-let
[
session
(
session-with-id
session-id
)]
(
when-not
(
session-expired?
session
)
{
:metabase-user-id
(
:user_id
session
)
:is-superuser?
(
:is_superuser
session
)}))))
(
defn-
add-current-user-info
[{
:keys
[
metabase-session-id
]
,
:as
request
}]
(
when-not
((
resolve
'metabase.core/initialized?
))
(
println
"Metabase is not initialized yet!"
))
; DEBUG
(
merge
request
(
current-user-info-for-session
metabase-session-id
)))
(
defn
wrap-current-user-id
"Add `:metabase-user-id` to the request if a valid session token was passed."
[
handler
]
(
comp
handler
add-current-user-i
d
))
(
comp
handler
add-current-user-i
nfo
))
(
defn
enforce-authentication
...
...
This diff is collapsed.
Click to expand it.
test/metabase/http_client.clj
+
1
−
0
View file @
6d1a1373
...
...
@@ -62,6 +62,7 @@
(
defn
authenticate
[{
:keys
[
email
password
]
:as
credentials
}]
{
:pre
[(
string?
email
)
(
string?
password
)]}
(
println
"Authenticating"
email
)
; DEBUG
(
try
(
:id
(
client
:post
200
"session"
credentials
))
(
catch
Throwable
e
...
...
This diff is collapsed.
Click to expand it.
test/metabase/permissions_collection_test.clj
+
1
−
1
View file @
6d1a1373
...
...
@@ -18,7 +18,7 @@
(
defn-
api-call-was-successful?
{
:style/indent
0
}
[
response
]
(
when
(
and
(
string?
response
)
(
not=
response
"You don't have permissions to do that."
))
(
println
"RESPONSE:"
[
response
]
))
(
println
"RESPONSE:"
response
))
; DEBUG
(
not=
response
"You don't have permissions to do that."
))
(
defn-
can-run-query?
[
username
]
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment