2017-02-17 00:34:45 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2019-10-25 00:27:02 +02:00
|
|
|
"github.com/kataras/iris/v12/httptest"
|
2017-02-17 00:34:45 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// $ go test -v
|
|
|
|
func TestNewApp(t *testing.T) {
|
2017-06-10 14:28:09 +02:00
|
|
|
app := newApp()
|
2017-06-15 19:02:08 +02:00
|
|
|
e := httptest.New(t, app)
|
2017-02-17 00:34:45 +01:00
|
|
|
|
2017-06-10 04:00:18 +02:00
|
|
|
// redirects to /admin without basic auth
|
2017-07-10 17:32:42 +02:00
|
|
|
e.GET("/").Expect().Status(httptest.StatusUnauthorized)
|
2017-06-10 04:00:18 +02:00
|
|
|
// without basic auth
|
2017-07-10 17:32:42 +02:00
|
|
|
e.GET("/admin").Expect().Status(httptest.StatusUnauthorized)
|
2017-06-10 04:00:18 +02:00
|
|
|
|
|
|
|
// with valid basic auth
|
|
|
|
e.GET("/admin").WithBasicAuth("myusername", "mypassword").Expect().
|
2017-07-10 17:32:42 +02:00
|
|
|
Status(httptest.StatusOK).Body().Equal("/admin myusername:mypassword")
|
2017-06-10 04:00:18 +02:00
|
|
|
e.GET("/admin/profile").WithBasicAuth("myusername", "mypassword").Expect().
|
2017-07-10 17:32:42 +02:00
|
|
|
Status(httptest.StatusOK).Body().Equal("/admin/profile myusername:mypassword")
|
2017-06-10 04:00:18 +02:00
|
|
|
e.GET("/admin/settings").WithBasicAuth("myusername", "mypassword").Expect().
|
2017-07-10 17:32:42 +02:00
|
|
|
Status(httptest.StatusOK).Body().Equal("/admin/settings myusername:mypassword")
|
2017-06-10 04:00:18 +02:00
|
|
|
|
|
|
|
// with invalid basic auth
|
|
|
|
e.GET("/admin/settings").WithBasicAuth("invalidusername", "invalidpassword").
|
2017-07-10 17:32:42 +02:00
|
|
|
Expect().Status(httptest.StatusUnauthorized)
|
2017-02-17 00:34:45 +01:00
|
|
|
}
|