Files
teleport/lib/msgraph/errors_test.go
T
Justinas Stankevičius c5a5f8e7a2 Replace MS Graph SDK with an in-house client (#44069)
* Add MS Graph client skeleton

* Complete retry logic

* Add GetID() to GroupMember

* Parse MS Graph API error responses

* Pull out page size into config

* Add missing "patch" methods to client interface

* Move code around

* Factor out roundtrip()

* Fill out remaining methods

* Add godocs and solve lints

* Run gci

* Move godocs to the interface

* Add missing method

* Finish errors_test

* close body in test

* nit

* Add license headers

* Move azureoidc onboarding code to msgraph.Client

* Make AzureTokenProvider public

* Use cmp.Or to shorten config defaults handling

* Address review nits

* Parallelize tests

* nit

* Respect context cancellation in retry logic

* Utilize BlockUntil in tests

* Remove Client interface, make client struct public

* Prefer defaults.HTTPClient to http.DefaultClient

* Iterate entra apps, do not buffer all in memory

* nit

* Set additional timeouts on default HTTP client

* Escape path segments when constructing URLs

* Add a general timeout for default HTTP client
2024-07-17 15:51:39 +00:00

66 lines
1.8 KiB
Go

// Teleport
// Copyright (C) 2024 Gravitational, Inc.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package msgraph
import (
"strings"
"testing"
"github.com/stretchr/testify/require"
)
const msGraphErrorPayload = `{
"error": {
"code": "Error_BadRequest",
"message": "Uploaded fragment overlaps with existing data.",
"innerError": {
"code": "invalidRange",
"request-id": "request-id",
"date": "date-time"
}
}
}`
func TestUnmarshalGraphError(t *testing.T) {
t.Parallel()
t.Run("valid", func(t *testing.T) {
graphError, err := readError(strings.NewReader(msGraphErrorPayload))
require.NoError(t, err)
require.NotNil(t, graphError)
expected := &GraphError{
Code: "Error_BadRequest",
Message: "Uploaded fragment overlaps with existing data.",
InnerError: &GraphError{
Code: "invalidRange",
},
}
require.Equal(t, expected, graphError)
})
t.Run("invalid", func(t *testing.T) {
_, err := readError(strings.NewReader("invalid json"))
require.Error(t, err)
})
t.Run("empty", func(t *testing.T) {
graphError, err := readError(strings.NewReader("{}"))
require.NoError(t, err)
require.Nil(t, graphError)
})
}