grafana/pkg/services/authn/authnimpl/usage_stats_test.go
Eric Leijonmarck 3cd952b8ba
Auth: Fix orgrole picker disabled if isSynced user (#64033)
* fix: disable orgrolepicker if externaluser is synced

* add disable to role picker

* just took me 2 hours to center the icon

* wip

* fix: check externallySyncedUser for API call

* remove check from store

* add: tests

* refactor authproxy and made tests run

* add: feature toggle

* set feature toggle for tests

* add: IsProviderEnabled

* refactor: featuretoggle name

* IsProviderEnabled tests

* add specific tests for isProviderEnabled

* fix: org_user tests

* add: owner to featuretoggle

* add missing authlabels

* remove fmt

* feature toggle

* change config

* add test for a different authmodule

* test refactor

* gen feature toggle again

* fix basic auth user able to change the org role

* test for basic auth role

* make err.base to error

* lowered lvl of log and input mesg
2023-03-22 17:41:59 +00:00

45 lines
1.4 KiB
Go

package authnimpl
import (
"context"
"testing"
"github.com/stretchr/testify/require"
"github.com/grafana/grafana/pkg/services/authn/authntest"
)
func TestService_getUsageStats(t *testing.T) {
svc := setupTests(t, func(svc *Service) {
svc.RegisterClient(
&authntest.FakeClient{ExpectedErr: nil, ExpectedName: "test", ExpectedPriority: 1, ExpectedStats: map[string]interface{}{"stats.test.enabled.count": 1}})
svc.RegisterClient(
&authntest.FakeClient{ExpectedErr: errCantAuthenticateReq, ExpectedName: "failing", ExpectedPriority: 1, ExpectedStats: nil})
})
svc.cfg.DisableLoginForm = false
svc.cfg.DisableLogin = false
svc.cfg.BasicAuthEnabled = true
svc.cfg.AuthProxyEnabled = true
svc.cfg.JWTAuthEnabled = true
svc.cfg.LDAPAuthEnabled = true
svc.cfg.EditorsCanAdmin = true
svc.cfg.ViewersCanEdit = true
got, err := svc.getUsageStats(context.Background())
require.NoError(t, err)
want := map[string]interface{}{"stats.auth_enabled.anonymous.count": 0,
"stats.auth_enabled.auth_proxy.count": 1,
"stats.auth_enabled.basic_auth.count": 1,
"stats.auth_enabled.grafana_password.count": 1,
"stats.auth_enabled.jwt.count": 1,
"stats.auth_enabled.ldap.count": 1,
"stats.auth_enabled.login_form.count": 1,
"stats.authz.editors_can_admin.count": 1,
"stats.authz.viewers_can_edit.count": 1,
"stats.test.enabled.count": 1,
}
require.Equal(t, want, got)
}