Telemetry(observations): add oidc and ldap observation events (#3945)
* telemetry(observations): Add observations for oidc and ldap authentications * telemetry(observations): Add tests ldap and oidc observation events
This commit is contained in:
1 parent
f0a4bce17c
commit
f9dee55e4d
5 files changed
+138
-12
No files matched your search
@@ -5,8 +5,12 @@ package authmethods_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
@@ -20,12 +24,14 @@ import (
|
||||
"github.com/hashicorp/boundary/internal/daemon/controller/handlers/authmethods"
|
||||
"github.com/hashicorp/boundary/internal/db"
|
||||
"github.com/hashicorp/boundary/internal/errors"
|
||||
"github.com/hashicorp/boundary/internal/event"
|
||||
pbs "github.com/hashicorp/boundary/internal/gen/controller/api/services"
|
||||
"github.com/hashicorp/boundary/internal/iam"
|
||||
"github.com/hashicorp/boundary/internal/kms"
|
||||
"github.com/hashicorp/boundary/internal/types/scope"
|
||||
pb "github.com/hashicorp/boundary/sdk/pbs/controller/api/resources/authmethods"
|
||||
scopepb "github.com/hashicorp/boundary/sdk/pbs/controller/api/resources/scopes"
|
||||
"github.com/hashicorp/eventlogger/formatter_filters/cloudevents"
|
||||
"github.com/hashicorp/go-hclog"
|
||||
"github.com/jimlambrt/gldap"
|
||||
"github.com/jimlambrt/gldap/testdirectory"
|
||||
@@ -876,7 +882,14 @@ func TestAuthenticate_Ldap(t *testing.T) {
|
||||
testRootWrapper := db.TestWrapper(t)
|
||||
testKms := kms.TestKms(t, testConn, testRootWrapper)
|
||||
o, _ := iam.TestScopes(t, iam.TestRepo(t, testConn, testRootWrapper))
|
||||
|
||||
opt := event.TestWithObservationSink(t)
|
||||
c := event.TestEventerConfig(t, "Test_StartAuth_to_Callback", opt)
|
||||
testLock := &sync.Mutex{}
|
||||
testLogger := hclog.New(&hclog.LoggerOptions{
|
||||
Mutex: testLock,
|
||||
Name: "test",
|
||||
})
|
||||
require.NoError(t, event.InitSysEventer(testLogger, testLock, "use-Test_Authenticate", event.WithEventerConfig(&c.EventerConfig)))
|
||||
iamRepoFn := func() (*iam.Repository, error) {
|
||||
return iam.TestRepo(t, testConn, testRootWrapper), nil
|
||||
}
|
||||
@@ -1094,7 +1107,20 @@ func TestAuthenticate_Ldap(t *testing.T) {
|
||||
assert.Equal(aToken.GetCreatedTime(), aToken.GetApproximateLastUsedTime())
|
||||
assert.Equal(testAm.GetPublicId(), aToken.GetAuthMethodId())
|
||||
assert.Equal(tc.wantType, resp.GetType())
|
||||
|
||||
sinkFileName := c.ObservationEvents.Name()
|
||||
defer func() { _ = os.WriteFile(sinkFileName, nil, 0o666) }()
|
||||
b, err := ioutil.ReadFile(sinkFileName)
|
||||
require.NoError(err)
|
||||
gotRes := &cloudevents.Event{}
|
||||
err = json.Unmarshal(b, gotRes)
|
||||
require.NoErrorf(err, "json: %s", string(b))
|
||||
details, ok := gotRes.Data.(map[string]any)["details"]
|
||||
require.True(ok)
|
||||
for _, key := range details.([]any) {
|
||||
assert.Contains(key.(map[string]any)["payload"], "user_id")
|
||||
assert.Contains(key.(map[string]any)["payload"], "auth_token_start")
|
||||
assert.Contains(key.(map[string]any)["payload"], "auth_token_end")
|
||||
}
|
||||
// support testing for pre-provisioned accounts
|
||||
if tc.acctId != "" {
|
||||
assert.Equal(tc.acctId, aToken.GetAccountId())
|
||||
|
||||
Reference in new issue
Block a user