mirror of
https://github.com/gabehf/Koito.git
synced 2026-04-22 20:11:50 -07:00
feat: add api key auth to web api (#183)
This commit is contained in:
parent
bf1c03e9fd
commit
42b32c7920
7 changed files with 418 additions and 332 deletions
|
|
@ -356,6 +356,38 @@ func TestDelete(t *testing.T) {
|
|||
truncateTestData(t)
|
||||
}
|
||||
|
||||
func TestLoginGate(t *testing.T) {
|
||||
|
||||
t.Run("Submit Listens", doSubmitListens)
|
||||
|
||||
req, err := http.NewRequest("DELETE", host()+"/apis/web/v1/artist?id=1", nil)
|
||||
require.NoError(t, err)
|
||||
req.Header.Add("Authorization", "Token "+apikey)
|
||||
resp, err := http.DefaultClient.Do(req)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, 204, resp.StatusCode)
|
||||
|
||||
cfg.SetLoginGate(true)
|
||||
|
||||
req, err = http.NewRequest("GET", host()+"/apis/web/v1/artist?id=3", nil)
|
||||
require.NoError(t, err)
|
||||
// req.Header.Add("Authorization", "Token "+apikey)
|
||||
resp, err = http.DefaultClient.Do(req)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, 401, resp.StatusCode)
|
||||
|
||||
req, err = http.NewRequest("GET", host()+"/apis/web/v1/artist?id=3", nil)
|
||||
require.NoError(t, err)
|
||||
req.Header.Add("Authorization", "Token "+apikey)
|
||||
resp, err = http.DefaultClient.Do(req)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, 200, resp.StatusCode)
|
||||
|
||||
cfg.SetLoginGate(false)
|
||||
|
||||
truncateTestData(t)
|
||||
}
|
||||
|
||||
func TestAliasesAndSearch(t *testing.T) {
|
||||
|
||||
t.Run("Submit Listens", doSubmitListens)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue