mirror of
https://github.com/kataras/iris.git
synced 2025-01-23 18:51:03 +01:00
ed45c77be5
Former-commit-id: ed635ee95de7160cde11eaabc0c1dcb0e460a620
30 lines
987 B
Go
30 lines
987 B
Go
package main
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/kataras/iris/v12/httptest"
|
|
)
|
|
|
|
func TestBasicAuth(t *testing.T) {
|
|
app := newApp()
|
|
e := httptest.New(t, app)
|
|
|
|
// redirects to /admin without basic auth
|
|
e.GET("/").Expect().Status(httptest.StatusUnauthorized)
|
|
// without basic auth
|
|
e.GET("/admin").Expect().Status(httptest.StatusUnauthorized)
|
|
|
|
// with valid basic auth
|
|
e.GET("/admin").WithBasicAuth("myusername", "mypassword").Expect().
|
|
Status(httptest.StatusOK).Body().Equal("/admin myusername:mypassword")
|
|
e.GET("/admin/profile").WithBasicAuth("myusername", "mypassword").Expect().
|
|
Status(httptest.StatusOK).Body().Equal("/admin/profile myusername:mypassword")
|
|
e.GET("/admin/settings").WithBasicAuth("myusername", "mypassword").Expect().
|
|
Status(httptest.StatusOK).Body().Equal("/admin/settings myusername:mypassword")
|
|
|
|
// with invalid basic auth
|
|
e.GET("/admin/settings").WithBasicAuth("invalidusername", "invalidpassword").
|
|
Expect().Status(httptest.StatusUnauthorized)
|
|
}
|