Files
teleport/lib/modules/modules_test.go
T
rosstimothy 9734fcbdbd Convert SetSessionRecordingConfig usages to new Create/Update/Upsert API (#39249)
Migrates callers off the deprecated API and onto the new API so
that SessionRecordingConfig can be protected via optimistic locking
when appropriate.
2024-03-15 19:55:57 +00:00

83 lines
2.5 KiB
Go

/*
* Teleport
* Copyright (C) 2023 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 modules_test
import (
"context"
"testing"
"github.com/stretchr/testify/require"
"github.com/gravitational/teleport/api/constants"
"github.com/gravitational/teleport/api/types"
"github.com/gravitational/teleport/lib/auth"
"github.com/gravitational/teleport/lib/modules"
)
func TestOSSModules(t *testing.T) {
require.False(t, modules.GetModules().IsBoringBinary())
require.Equal(t, modules.BuildOSS, modules.GetModules().BuildType())
}
func TestValidateAuthPreferenceOnCloud(t *testing.T) {
ctx := context.Background()
testServer, err := auth.NewTestAuthServer(auth.TestAuthServerConfig{
Dir: t.TempDir(),
})
require.NoError(t, err)
modules.SetTestModules(t, &modules.TestModules{
TestBuildType: modules.BuildEnterprise,
TestFeatures: modules.Features{
Cloud: true,
},
})
authPref, err := testServer.AuthServer.UpsertAuthPreference(ctx, types.DefaultAuthPreference())
require.NoError(t, err)
authPref.SetSecondFactor(constants.SecondFactorOff)
_, err = testServer.AuthServer.UpdateAuthPreference(ctx, authPref)
require.EqualError(t, err, "cannot disable two-factor authentication on Cloud")
}
func TestValidateSessionRecordingConfigOnCloud(t *testing.T) {
ctx := context.Background()
testServer, err := auth.NewTestAuthServer(auth.TestAuthServerConfig{
Dir: t.TempDir(),
})
require.NoError(t, err)
modules.SetTestModules(t, &modules.TestModules{
TestBuildType: modules.BuildEnterprise,
TestFeatures: modules.Features{
Cloud: true,
},
})
recConfig := types.DefaultSessionRecordingConfig()
_, err = testServer.AuthServer.UpsertSessionRecordingConfig(ctx, recConfig)
require.NoError(t, err)
recConfig.SetMode(types.RecordAtProxy)
_, err = testServer.AuthServer.UpsertSessionRecordingConfig(ctx, recConfig)
require.EqualError(t, err, "cannot set proxy recording mode on Cloud")
}