2022-11-07 10:46:19 +00:00
|
|
|
package secretscan
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
|
|
|
|
|
"github.com/grafana/grafana/pkg/services/apikey"
|
|
|
|
|
"github.com/grafana/grafana/pkg/services/serviceaccounts"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type MockTokenRetriever struct {
|
|
|
|
|
keys []apikey.APIKey
|
|
|
|
|
errList error
|
|
|
|
|
errRevoke error
|
|
|
|
|
|
2023-08-30 08:46:47 -07:00
|
|
|
listCalls []any
|
|
|
|
|
revokeCalls [][]any
|
2022-11-07 10:46:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (m *MockTokenRetriever) ListTokens(
|
|
|
|
|
ctx context.Context, query *serviceaccounts.GetSATokensQuery,
|
|
|
|
|
) ([]apikey.APIKey, error) {
|
|
|
|
|
m.listCalls = append(m.listCalls, query)
|
|
|
|
|
|
|
|
|
|
return m.keys, m.errList
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (m *MockTokenRetriever) RevokeServiceAccountToken(
|
|
|
|
|
ctx context.Context, orgID, serviceAccountID, tokenID int64,
|
|
|
|
|
) error {
|
2023-08-30 08:46:47 -07:00
|
|
|
m.revokeCalls = append(m.revokeCalls, []any{orgID, serviceAccountID, tokenID})
|
2022-11-07 10:46:19 +00:00
|
|
|
|
|
|
|
|
return m.errRevoke
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type MockSecretScaner struct{}
|
|
|
|
|
|
|
|
|
|
func (m *MockSecretScaner) CheckTokens(ctx context.Context) error {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type MockSecretScanClient struct {
|
|
|
|
|
tokens []Token
|
|
|
|
|
err error
|
|
|
|
|
|
2023-08-30 08:46:47 -07:00
|
|
|
checkCalls []any
|
2022-11-07 10:46:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (m *MockSecretScanClient) CheckTokens(ctx context.Context, keyHashes []string) ([]Token, error) {
|
|
|
|
|
m.checkCalls = append(m.checkCalls, keyHashes)
|
|
|
|
|
|
|
|
|
|
return m.tokens, m.err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type MockSecretScanNotifier struct {
|
|
|
|
|
err error
|
|
|
|
|
|
2023-08-30 08:46:47 -07:00
|
|
|
notifyCalls [][]any
|
2022-11-07 10:46:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (m *MockSecretScanNotifier) Notify(ctx context.Context,
|
|
|
|
|
token *Token, tokenName string, revoked bool,
|
|
|
|
|
) error {
|
2023-08-30 08:46:47 -07:00
|
|
|
m.notifyCalls = append(m.notifyCalls, []any{token, tokenName, revoked})
|
2022-11-07 10:46:19 +00:00
|
|
|
|
|
|
|
|
return m.err
|
|
|
|
|
}
|