Files
teleport/lib/circleci/token_source_test.go
T
Noah StrideandZac Bergquist 291d6d53a6 CircleCI Secure Joining (#17626)
* Add API types for CircleCI joining

* Add validation for CircleCI configuration

* Add JoinMethodCircleCI across codebase

* Add token validator and token source for circleci

* Update join methods RFD

* Add CircleCI token source to register.go

* Add serverside support for circleci joining

* Add test for TokenSource

* Add success case for token validation test

* Add expired test case

* Add test case for token from another org

* Test RegisterWithToken for CircleCI

* Refactor GitHub RegisterUsingToken tests

* Refactor CircleCI RegisterUsingToken tests

* Add tests for ProvisionTokenSpecV2

* Appease linters

* Go Imports files

* Fix failing test for msising IDtoken

* Update lib/auth/join_circleci.go

Co-authored-by: Zac Bergquist <zac.bergquist@goteleport.com>

* Move test server cleanup closer to initialisation

* Fix weird import reordering

* Include unexpected type in error message

* Simplify boolean algebra :)

Co-authored-by: Zac Bergquist <zac.bergquist@goteleport.com>
2022-11-01 12:15:10 +00:00

66 lines
1.5 KiB
Go

/*
Copyright 2022 Gravitational, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package circleci
import (
"testing"
"github.com/gravitational/trace"
"github.com/stretchr/testify/require"
)
func TestGetIDToken(t *testing.T) {
t.Parallel()
fakeGetEnv := func(env string) getEnvFunc {
return func(key string) string {
if key == "CIRCLE_OIDC_TOKEN" {
return env
}
return ""
}
}
tests := []struct {
name string
getEnv getEnvFunc
wantString string
assertError require.ErrorAssertionFunc
}{
{
name: "success",
getEnv: fakeGetEnv("foobarbizz"),
wantString: "foobarbizz",
assertError: require.NoError,
},
{
name: "unset",
getEnv: fakeGetEnv(""),
assertError: func(t require.TestingT, err error, i ...interface{}) {
require.True(t, trace.IsBadParameter(err))
},
},
}
for _, tt := range tests {
t.Run(t.Name(), func(t *testing.T) {
str, err := GetIDToken(tt.getEnv)
require.Equal(t, tt.wantString, str)
tt.assertError(t, err)
})
}
}