Skip to content

Commit

Permalink
UPSTREAM: <carry>: use new access token inactivity timeout field.
Browse files Browse the repository at this point in the history
  • Loading branch information
vareti authored and damemi committed Dec 20, 2021
1 parent d1e5363 commit 79be142
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
Expand Up @@ -72,10 +72,10 @@ func validateOAuthSpec(spec configv1.OAuthSpec) field.ErrorList {
}

// TODO move to ValidateTokenConfig
timeout := spec.TokenConfig.AccessTokenInactivityTimeoutSeconds
if timeout > 0 && timeout < MinimumInactivityTimeoutSeconds {
timeout := spec.TokenConfig.AccessTokenInactivityTimeout
if timeout != nil && timeout.Seconds() < MinimumInactivityTimeoutSeconds {
errs = append(errs, field.Invalid(
specPath.Child("tokenConfig", "accessTokenInactivityTimeoutSeconds"), timeout,
specPath.Child("tokenConfig", "accessTokenInactivityTimeout"), timeout,
fmt.Sprintf("the minimum acceptable token timeout value is %d seconds",
MinimumInactivityTimeoutSeconds)))
}
Expand Down
Expand Up @@ -4,7 +4,9 @@ import (
"fmt"
"reflect"
"testing"
"time"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/validation/field"

configv1 "github.com/openshift/api/config/v1"
Expand Down Expand Up @@ -143,17 +145,20 @@ func TestValidateOAuthSpec(t *testing.T) {
args: args{
spec: configv1.OAuthSpec{
TokenConfig: configv1.TokenConfig{
AccessTokenInactivityTimeoutSeconds: -50,
AccessTokenInactivityTimeout: &metav1.Duration{Duration: -50 * time.Second},
},
},
},
want: field.ErrorList{
field.Invalid(field.NewPath("spec", "tokenConfig", "accessTokenInactivityTimeout"), metav1.Duration{Duration: -50 * time.Second}, fmt.Sprintf("the minimum acceptable token timeout value is %d seconds", MinimumInactivityTimeoutSeconds)),
},
},
{
name: "positive token inactivity timeout",
args: args{
spec: configv1.OAuthSpec{
TokenConfig: configv1.TokenConfig{
AccessTokenInactivityTimeoutSeconds: 32578,
AccessTokenInactivityTimeout: &metav1.Duration{Duration: 32578 * time.Second},
},
},
},
Expand All @@ -163,22 +168,25 @@ func TestValidateOAuthSpec(t *testing.T) {
args: args{
spec: configv1.OAuthSpec{
TokenConfig: configv1.TokenConfig{
AccessTokenInactivityTimeoutSeconds: 0,
AccessTokenInactivityTimeout: &metav1.Duration{Duration: 0},
},
},
},
want: field.ErrorList{
field.Invalid(field.NewPath("spec", "tokenConfig", "accessTokenInactivityTimeout"), metav1.Duration{Duration: 0 * time.Second}, fmt.Sprintf("the minimum acceptable token timeout value is %d seconds", MinimumInactivityTimeoutSeconds)),
},
},
{
name: "token inactivity timeout lower than the api constant minimum",
args: args{
spec: configv1.OAuthSpec{
TokenConfig: configv1.TokenConfig{
AccessTokenInactivityTimeoutSeconds: 250,
AccessTokenInactivityTimeout: &metav1.Duration{Duration: 250 * time.Second},
},
},
},
want: field.ErrorList{
field.Invalid(field.NewPath("spec", "tokenConfig", "accessTokenInactivityTimeoutSeconds"), 250, fmt.Sprintf("the minimum acceptable token timeout value is %d seconds", MinimumInactivityTimeoutSeconds)),
field.Invalid(field.NewPath("spec", "tokenConfig", "accessTokenInactivityTimeout"), metav1.Duration{Duration: 250 * time.Second}, fmt.Sprintf("the minimum acceptable token timeout value is %d seconds", MinimumInactivityTimeoutSeconds)),
},
},
{
Expand Down Expand Up @@ -246,8 +254,8 @@ func TestValidateOAuthSpec(t *testing.T) {
},
},
TokenConfig: configv1.TokenConfig{
AccessTokenInactivityTimeoutSeconds: -1,
AccessTokenMaxAgeSeconds: 216000,
AccessTokenInactivityTimeout: &metav1.Duration{Duration: 300 * time.Second},
AccessTokenMaxAgeSeconds: 216000,
},
Templates: configv1.OAuthTemplates{
Login: configv1.SecretNameReference{Name: "my-login-template"},
Expand Down

0 comments on commit 79be142

Please sign in to comment.