mirror of
https://github.com/kataras/iris.git
synced 2025-12-18 18:37:05 +00:00
more features and fix database/mysql:jwt example
This commit is contained in:
29
_examples/auth/basicauth/basic/main_test.go
Normal file
29
_examples/auth/basicauth/basic/main_test.go
Normal file
@@ -0,0 +1,29 @@
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user