Skip to content
This repository has been archived by the owner on Oct 11, 2024. It is now read-only.

Skip ms auth checks for gock client #5163

Merged
merged 1 commit into from
Jan 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions src/pkg/services/m365/api/graph/service_mock.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package graph

import (
"context"

"github.com/alcionai/clues"
"github.com/h2non/gock"
abstractions "github.com/microsoft/kiota-abstractions-go"
Expand All @@ -10,6 +12,23 @@ import (
"github.com/alcionai/corso/src/pkg/count"
)

// authMock implements the
// github.com/microsoft.kiota-abstractions-go/authentication:AuthenticationProvider
// interface.
type authMock struct{}

// AuthenticateRequest is the function called prior to sending a graph API
// request. It ensures the client has the proper authentication to send the
// request. Returning nil allows us to skip the authentication that would
// normally happen.
func (a authMock) AuthenticateRequest(
context.Context,
*abstractions.RequestInformation,
map[string]any,
) error {
return nil
}

func NewGockService(
creds account.M365Config,
counter *count.Bus,
Expand All @@ -35,19 +54,16 @@ func CreateGockAdapter(
counter *count.Bus,
opts ...Option,
) (abstractions.RequestAdapter, error) {
auth, err := GetAuth(tenant, client, secret)
if err != nil {
return nil, err
}

httpClient, cc := KiotaHTTPClient(counter, opts...)

// This makes sure that we are able to intercept any requests via
// gock. Only necessary for testing.
gock.InterceptClient(httpClient)

ng, err := msgraphsdkgo.NewGraphRequestAdapterWithParseNodeFactoryAndSerializationWriterFactoryAndHttpClient(
auth,
// Use our own mock auth instance. This allows us to completely avoid having
// to make requests to microsoft servers during testing.
authMock{},
nil, nil,
httpClient)

Expand Down
Loading