Skip ms auth checks for gock client (#5163)
Disable sending requests to microsoft servers to get API tokens when using the gock client. This is accomplished by passing in a mock that always returns no error for auth requests. **This PR does not go through and make existing tests using gock unit tests instead of integration tests. That will need to be done separately** --- #### Does this PR need a docs update or release note? - [ ] ✅ Yes, it's included - [ ] 🕐 Yes, but in a later PR - [x] ⛔ No #### Type of change - [ ] 🌻 Feature - [ ] 🐛 Bugfix - [ ] 🗺️ Documentation - [x] 🤖 Supportability/Tests - [ ] 💻 CI/Deployment - [ ] 🧹 Tech Debt/Cleanup #### Issue(s) * #5124 #### Test Plan - [x] 💪 Manual - [ ] ⚡ Unit test - [ ] 💚 E2E
This commit is contained in:
parent
45b021d58e
commit
d2f1bbb5c7
@ -1,6 +1,8 @@
|
|||||||
package graph
|
package graph
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
"github.com/alcionai/clues"
|
"github.com/alcionai/clues"
|
||||||
"github.com/h2non/gock"
|
"github.com/h2non/gock"
|
||||||
abstractions "github.com/microsoft/kiota-abstractions-go"
|
abstractions "github.com/microsoft/kiota-abstractions-go"
|
||||||
@ -10,6 +12,23 @@ import (
|
|||||||
"github.com/alcionai/corso/src/pkg/count"
|
"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(
|
func NewGockService(
|
||||||
creds account.M365Config,
|
creds account.M365Config,
|
||||||
counter *count.Bus,
|
counter *count.Bus,
|
||||||
@ -35,11 +54,6 @@ func CreateGockAdapter(
|
|||||||
counter *count.Bus,
|
counter *count.Bus,
|
||||||
opts ...Option,
|
opts ...Option,
|
||||||
) (abstractions.RequestAdapter, error) {
|
) (abstractions.RequestAdapter, error) {
|
||||||
auth, err := GetAuth(tenant, client, secret)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
httpClient, cc := KiotaHTTPClient(counter, opts...)
|
httpClient, cc := KiotaHTTPClient(counter, opts...)
|
||||||
|
|
||||||
// This makes sure that we are able to intercept any requests via
|
// This makes sure that we are able to intercept any requests via
|
||||||
@ -47,7 +61,9 @@ func CreateGockAdapter(
|
|||||||
gock.InterceptClient(httpClient)
|
gock.InterceptClient(httpClient)
|
||||||
|
|
||||||
ng, err := msgraphsdkgo.NewGraphRequestAdapterWithParseNodeFactoryAndSerializationWriterFactoryAndHttpClient(
|
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,
|
nil, nil,
|
||||||
httpClient)
|
httpClient)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user