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
d3968900
Unverified
Commit
d3968900
authored
2 years ago
by
Tim Macdonald
Committed by
GitHub
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Notify endpoint should 404 with incorrect table name/id (#25627) (#25703)
parent
275b24f4
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/api/notify.clj
+2
-2
2 additions, 2 deletions
src/metabase/api/notify.clj
test/metabase/api/notify_test.clj
+36
-15
36 additions, 15 deletions
test/metabase/api/notify_test.clj
test/metabase/server/middleware/auth_test.clj
+4
-4
4 additions, 4 deletions
test/metabase/server/middleware/auth_test.clj
with
42 additions
and
21 deletions
src/metabase/api/notify.clj
+
2
−
2
View file @
d3968900
...
...
@@ -32,9 +32,9 @@
(
thunk
)))]
(
api/let-404
[
database
(
db/select-one
Database
:id
id
)]
(
cond
table_id
(
when-let
[
table
(
db/select-one
Table
:db_id
id,
:id
(
int
table_id
))]
table_id
(
api/let-404
[
table
(
db/select-one
Table
:db_id
id,
:id
(
int
table_id
))]
(
execute!
#
(
table-sync-fn
table
)))
table_name
(
when-let
[
table
(
db/select-one
Table
:db_id
id,
:name
table_name
)]
table_name
(
api/let-404
[
table
(
db/select-one
Table
:db_id
id,
:name
table_name
)]
(
execute!
#
(
table-sync-fn
table
)))
:else
(
execute!
#
(
db-sync-fn
database
)))))
{
:success
true
})
...
...
This diff is collapsed.
Click to expand it.
test/metabase/api/notify_test.clj
+
36
−
15
View file @
d3968900
...
...
@@ -19,17 +19,39 @@
(
is
(
=
(
get
mw.util/response-forbidden
:body
)
(
client/client
:post
403
"notify/db/100"
))))))
(
def
api-headers
{
:headers
{
"X-METABASE-APIKEY"
"test-api-key"
"Content-Type"
"application/json"
}})
(
deftest
not-found-test
(
testing
"POST /api/notify/db/:id"
(
testing
"database must exist or we get a 404"
(
is
(
=
{
:status
404
:body
"Not found."
}
(
try
(
http/post
(
client/build-url
(
format
"notify/db/%d"
Integer/MAX_VALUE
)
{})
{
:accept
:json
:headers
{
"X-METABASE-APIKEY"
"test-api-key"
"Content-Type"
"application/json"
}})
(
catch
clojure.lang.ExceptionInfo
e
(
select-keys
(
ex-data
e
)
[
:status
:body
]))))))))
(
mt/with-temporary-setting-values
[
api-key
"test-api-key"
]
(
testing
"POST /api/notify/db/:id"
(
testing
"database must exist or we get a 404"
(
is
(
=
{
:status
404
:body
"Not found."
}
(
try
(
http/post
(
client/build-url
(
format
"notify/db/%d"
Integer/MAX_VALUE
)
{})
(
merge
{
:accept
:json
}
api-headers
))
(
catch
clojure.lang.ExceptionInfo
e
(
select-keys
(
ex-data
e
)
[
:status
:body
]))))))
(
testing
"table ID must exist or we get a 404"
(
is
(
=
{
:status
404
:body
"Not found."
}
(
try
(
http/post
(
client/build-url
(
format
"notify/db/%d"
(
:id
(
mt/db
)))
{})
(
merge
{
:accept
:json
:content-type
:json
:form-params
{
:table_id
Integer/MAX_VALUE
}}
api-headers
))
(
catch
clojure.lang.ExceptionInfo
e
(
select-keys
(
ex-data
e
)
[
:status
:body
]))))))
(
testing
"table name must exist or we get a 404"
(
is
(
=
{
:status
404
:body
"Not found."
}
(
try
(
http/post
(
client/build-url
(
format
"notify/db/%d"
(
:id
(
mt/db
)))
{})
(
merge
{
:accept
:json
:content-type
:json
:form-params
{
:table_name
"IncorrectToucanFact"
}}
api-headers
))
(
catch
clojure.lang.ExceptionInfo
e
(
select-keys
(
ex-data
e
)
[
:status
:body
])))))))))
(
deftest
post-db-id-test
(
binding
[
api.notify/*execute-asynchronously*
false
]
...
...
@@ -38,11 +60,10 @@
post
(
fn
post-api
([
payload
]
(
post-api
payload
200
))
([
payload
expected-code
]
(
mt/client
:post
expected-code
(
format
"notify/db/%d"
(
u/the-id
(
mt/db
)))
{
:request-options
{
:headers
{
"X-METABASE-APIKEY"
"test-api-key"
"Content-Type"
"application/json"
}}}
payload
)))]
(
mt/with-temporary-setting-values
[
api-key
"test-api-key"
]
(
mt/client
:post
expected-code
(
format
"notify/db/%d"
(
u/the-id
(
mt/db
)))
{
:request-options
api-headers
}
payload
))))]
(
testing
"sync just table when table is provided"
(
let
[
long-sync-called?
(
atom
false
)
,
short-sync-called?
(
atom
false
)]
(
with-redefs
[
metabase.sync/sync-table!
(
fn
[
_table
]
(
reset!
long-sync-called?
true
))
...
...
This diff is collapsed.
Click to expand it.
test/metabase/server/middleware/auth_test.clj
+
4
−
4
View file @
d3968900
...
...
@@ -91,10 +91,10 @@
(
deftest
wrap-api-key-test
(
testing
"No API key in the request"
(
is
(
=
nil
(
:metabase-session-id
(
wrapped-api-key-handler
(
ring.mock/request
:get
"/anyurl"
))))))
(
is
(
nil
?
(
:metabase-session-id
(
wrapped-api-key-handler
(
ring.mock/request
:get
"/anyurl"
))))))
(
testing
"API Key in header"
(
is
(
=
"foobar"
...
...
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