mirror of
https://github.com/kataras/iris.git
synced 2025-01-24 11:11:03 +01:00
dd26fbf26d
Former-commit-id: 3c5f6c97629a2a6ae44e62f2900edd32c0329b50
34 lines
1.1 KiB
Go
34 lines
1.1 KiB
Go
package main
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/kataras/iris"
|
|
"github.com/kataras/iris/httptest"
|
|
)
|
|
|
|
// $ cd _example
|
|
// $ go test -v
|
|
func TestNewApp(t *testing.T) {
|
|
app := buildApp()
|
|
e := httptest.New(app, t)
|
|
|
|
// redirects to /admin without basic auth
|
|
e.GET("/").Expect().Status(iris.StatusUnauthorized)
|
|
// without basic auth
|
|
e.GET("/admin").Expect().Status(iris.StatusUnauthorized)
|
|
|
|
// with valid basic auth
|
|
e.GET("/admin").WithBasicAuth("myusername", "mypassword").Expect().
|
|
Status(iris.StatusOK).Body().Equal("Hello authenticated user: myusername from: /admin")
|
|
e.GET("/admin/profile").WithBasicAuth("myusername", "mypassword").Expect().
|
|
Status(iris.StatusOK).Body().Equal("Hello authenticated user: myusername from: /admin/profile")
|
|
e.GET("/admin/settings").WithBasicAuth("myusername", "mypassword").Expect().
|
|
Status(iris.StatusOK).Body().Equal("Hello authenticated user: myusername from: /admin/settings")
|
|
|
|
// with invalid basic auth
|
|
e.GET("/admin/settings").WithBasicAuth("invalidusername", "invalidpassword").
|
|
Expect().Status(iris.StatusUnauthorized)
|
|
|
|
}
|