|
|
@@ -8,7 +8,6 @@ import (
|
|
|
"github.com/grafana/grafana/pkg/bus"
|
|
|
"github.com/grafana/grafana/pkg/middleware"
|
|
|
m "github.com/grafana/grafana/pkg/models"
|
|
|
- "github.com/grafana/grafana/pkg/services/auth"
|
|
|
"gopkg.in/macaron.v1"
|
|
|
|
|
|
. "github.com/smartystreets/goconvey/convey"
|
|
|
@@ -95,14 +94,13 @@ func (sc *scenarioContext) fakeReqWithParams(method, url string, queryParams map
|
|
|
}
|
|
|
|
|
|
type scenarioContext struct {
|
|
|
- m *macaron.Macaron
|
|
|
- context *m.ReqContext
|
|
|
- resp *httptest.ResponseRecorder
|
|
|
- handlerFunc handlerFunc
|
|
|
- defaultHandler macaron.Handler
|
|
|
- req *http.Request
|
|
|
- url string
|
|
|
- userAuthTokenService *fakeUserAuthTokenService
|
|
|
+ m *macaron.Macaron
|
|
|
+ context *m.ReqContext
|
|
|
+ resp *httptest.ResponseRecorder
|
|
|
+ handlerFunc handlerFunc
|
|
|
+ defaultHandler macaron.Handler
|
|
|
+ req *http.Request
|
|
|
+ url string
|
|
|
}
|
|
|
|
|
|
func (sc *scenarioContext) exec() {
|
|
|
@@ -124,76 +122,7 @@ func setupScenarioContext(url string) *scenarioContext {
|
|
|
Delims: macaron.Delims{Left: "[[", Right: "]]"},
|
|
|
}))
|
|
|
|
|
|
- sc.userAuthTokenService = newFakeUserAuthTokenService()
|
|
|
- sc.m.Use(middleware.GetContextHandler(sc.userAuthTokenService))
|
|
|
+ sc.m.Use(middleware.GetContextHandler(nil))
|
|
|
|
|
|
return sc
|
|
|
}
|
|
|
-
|
|
|
-type fakeUserToken interface {
|
|
|
- auth.UserToken
|
|
|
- SetToken(token string)
|
|
|
-}
|
|
|
-
|
|
|
-type userTokenImpl struct {
|
|
|
- userId int64
|
|
|
- token string
|
|
|
-}
|
|
|
-
|
|
|
-func (ut *userTokenImpl) GetUserId() int64 {
|
|
|
- return ut.userId
|
|
|
-}
|
|
|
-
|
|
|
-func (ut *userTokenImpl) GetToken() string {
|
|
|
- return ut.token
|
|
|
-}
|
|
|
-
|
|
|
-func (ut *userTokenImpl) SetToken(token string) {
|
|
|
- ut.token = token
|
|
|
-}
|
|
|
-
|
|
|
-type fakeUserAuthTokenService struct {
|
|
|
- createTokenProvider func(userId int64, clientIP, userAgent string) (auth.UserToken, error)
|
|
|
- tryRotateTokenProvider func(token auth.UserToken, clientIP, userAgent string) (bool, error)
|
|
|
- lookupTokenProvider func(unhashedToken string) (auth.UserToken, error)
|
|
|
- revokeTokenProvider func(token auth.UserToken) error
|
|
|
-}
|
|
|
-
|
|
|
-func newFakeUserAuthTokenService() *fakeUserAuthTokenService {
|
|
|
- return &fakeUserAuthTokenService{
|
|
|
- createTokenProvider: func(userId int64, clientIP, userAgent string) (auth.UserToken, error) {
|
|
|
- return &userTokenImpl{
|
|
|
- userId: 0,
|
|
|
- token: "",
|
|
|
- }, nil
|
|
|
- },
|
|
|
- tryRotateTokenProvider: func(token auth.UserToken, clientIP, userAgent string) (bool, error) {
|
|
|
- return false, nil
|
|
|
- },
|
|
|
- lookupTokenProvider: func(unhashedToken string) (auth.UserToken, error) {
|
|
|
- return &userTokenImpl{
|
|
|
- userId: 0,
|
|
|
- token: "",
|
|
|
- }, nil
|
|
|
- },
|
|
|
- revokeTokenProvider: func(token auth.UserToken) error {
|
|
|
- return nil
|
|
|
- },
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-func (s *fakeUserAuthTokenService) CreateToken(userId int64, clientIP, userAgent string) (auth.UserToken, error) {
|
|
|
- return s.createTokenProvider(userId, clientIP, userAgent)
|
|
|
-}
|
|
|
-
|
|
|
-func (s *fakeUserAuthTokenService) LookupToken(unhashedToken string) (auth.UserToken, error) {
|
|
|
- return s.lookupTokenProvider(unhashedToken)
|
|
|
-}
|
|
|
-
|
|
|
-func (s *fakeUserAuthTokenService) TryRotateToken(token auth.UserToken, clientIP, userAgent string) (bool, error) {
|
|
|
- return s.tryRotateTokenProvider(token, clientIP, userAgent)
|
|
|
-}
|
|
|
-
|
|
|
-func (s *fakeUserAuthTokenService) RevokeToken(token auth.UserToken) error {
|
|
|
- return s.revokeTokenProvider(token)
|
|
|
-}
|