Files
teleport/lib/auth/methods_test.go
T
rosstimothy 7fe7a6b2a0 Replace dependencies on lib/auth with lib/authclient (#41623)
* Remove authclient.Client/ClientI/NewClient aliases in lib/auth

* Remove WebSessionReq aliases in lib/auth

* Remove GithubAuthResponse aliases in lib/auth

* Remove GithubAuthRequest aliases in lib/auth

* Remove KubeCSR alias in lib/auth

* Remove KubeCSRResponse alias in lib/auth

* Remove OIDCAuthResponse alias in lib/auth

* Remove OIDCAuthRequest alias in lib/auth

* Remove ValidateOIDCAuthCallbackReq alias in lib/auth

* Remove OIDCAuthRawResponse alias in lib/auth

* Remove CreateUserTokenRequest alias in lib/auth

* Remove SAMLAuthResponse alias in lib/auth

* Remove SAMLAuthRequest alias in lib/auth

* Remove ValidateSAMLResponseReq alias in lib/auth

* Remove SAMLAuthRawResponse alias in lib/auth

* Remove ValidateTrustedClusterRequest alias in lib/auth

* Remove ValidateTrustedClusterRequestRaw alias in lib/auth

* Remove ValidateTrustedClusterResponse alias in lib/auth

* Remove ValidateTrustedClusterResponseRaw alias in lib/auth

* Remove AuthenticateUserRequest alias in lib/auth

* Remove ForwardedClientMetadata alias in lib/auth

* Remove PassCreds alias in lib/auth

* Remove OTPCreds alias in lib/auth

* Remove SessionCreds alias in lib/auth

* Remove AuthenticateSSHRequest alias in lib/auth

* Remove SSHLoginResponse alias in lib/auth

* Remove TrustedCerts alias in lib/auth

* Remove AuthoritiesToTrustedCerts alias in lib/auth

* Move auth.HostFQDN to authclient

* Move auth.WithClusterCAs, auth.DefaultClientCertPool and auth.ClientCertPool to authclient

* Switch alpn proxy to use authclient.CAGetter instead of auth.ReadProxyAccessPoint

* Use a smaller scoped interfaces in lib/proxy/peer to remove lib/auth dependency

* Move auth.TryCreateAppSessionForClientCertV15 to authclient

* Move auth.ErrNoMFADevices to authclient

* Move access point interfaces to authclient. Aliases left behind to prevent breaking builds

* remove lib/auth dependency from lib/reversetunnelclient

* fix lints

* fix license

* Bump e ref to include gravitational/teleport.e#4174

* Use authclient.Client in new tctl diag commands

* Stop using auth.UserTokenType aliases
2024-05-16 17:34:58 +00:00

73 lines
4.1 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 auth
import (
"context"
"strings"
"testing"
"github.com/stretchr/testify/require"
apievents "github.com/gravitational/teleport/api/types/events"
"github.com/gravitational/teleport/lib/auth/authclient"
"github.com/gravitational/teleport/lib/events/eventstest"
)
func TestServerAuthenticateUserUserAgentTrim(t *testing.T) {
ctx := context.Background()
emitter := &eventstest.MockRecorderEmitter{}
r := authclient.AuthenticateUserRequest{
ClientMetadata: &authclient.ForwardedClientMetadata{
UserAgent: strings.Repeat("A", maxUserAgentLen+1),
},
}
// Ignoring the error here because we really just care that the event was logged.
(&Server{emitter: emitter}).authenticateUserLogin(ctx, r)
event := emitter.LastEvent()
loginEvent, ok := event.(*apievents.UserLogin)
require.True(t, ok)
require.LessOrEqual(t, len(loginEvent.UserAgent), maxUserAgentLen)
}
func Test_trimUserAgent(t *testing.T) {
tests := []struct {
name string
inputUserAgent string
wantUserAgent string
}{
{
name: "short",
inputUserAgent: "foo/1.0",
wantUserAgent: "foo/1.0",
},
{
name: "trimmed",
inputUserAgent: strings.Repeat("foo/1.0 ", 500),
wantUserAgent: "foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1.0 foo/1...",
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
require.Equal(t, test.wantUserAgent, trimUserAgent(test.inputUserAgent))
})
}
}