Files
OpenShell/sdk/go/openshell/v1/oidc/errors_test.go
Roland HussandDrew Newberry 8dc55e21ee feat(sdk/go): complete Go SDK with domain clients, auth, and hardening (#2702)
* feat(sdk/go): complete Go SDK with domain clients, auth, and hardening

Add the Go SDK implementation covering all gateway RPC services with
domain-typed clients, comprehensive OIDC authentication flows, fake
test doubles, and proto converters.

Domain clients: Sandbox, Provider, Exec, File, TCP, SSH, Policy,
Profile, Health, Service, Config, Workspace, Inference, Refresh.
Each client validates inputs, resolves sandboxes by name, and converts
between domain types and proto at the boundary.

Auth: OIDC authorization code (PKCE), device code (RFC 8628), and
client credentials (RFC 6749 Section 4.4) flows with gateway config
auto-resolution. Token refresh with singleflight deduplication and
exponential backoff. Edge tunnel proxy for gRPC-over-WebSocket.

Gateway: On-disk gateway discovery with user/system directory
precedence, lazy token loading, and auth mode mapping.

Testing: In-memory fake client with deep-copy isolation, watch
broadcasting with filtering, and workspace-scoped object stores.
Bufconn-based gRPC tests for all domain clients.

Ref: #2044

Signed-off-by: Roland Huß <rhuss@redhat.com>

* feat(sdk/go): add gateway client options for logger, timeout, and retry

Add WithLogger, WithTimeout, and WithRetryPolicy options to the gateway
package's NewClient function. These forward the corresponding Config
fields (Logger, Timeout, RetryPolicy) through to the underlying SDK
client, giving callers full control over observability, connection
timeouts, and retry behavior when constructing clients from on-disk
gateway configurations.

Also adds RetryPolicy type to types package and extends Config with the
three new fields.

* fix(mise): sync sccache lock entry

Signed-off-by: Drew Newberry <anewberry@nvidia.com>

---------

Signed-off-by: Roland Huß <rhuss@redhat.com>
Signed-off-by: Drew Newberry <anewberry@nvidia.com>
Co-authored-by: Drew Newberry <anewberry@nvidia.com>
2026-08-13 19:15:21 +00:00

108 lines
2.4 KiB
Go

// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
package oidc
import (
"errors"
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
func TestSentinelErrors_AreDistinct(t *testing.T) {
sentinels := []error{
ErrDiscovery,
ErrAuthCode,
ErrDeviceCode,
ErrClientCredentials,
ErrTimeout,
ErrCallbackServer,
ErrTokenPersist,
ErrOIDCConfig,
}
for i, a := range sentinels {
for j, b := range sentinels {
if i == j {
continue
}
assert.False(t, errors.Is(a, b),
"expected %v and %v to be distinct", a, b)
}
}
}
func TestSentinelErrors_MatchSelf(t *testing.T) {
sentinels := []error{
ErrDiscovery,
ErrAuthCode,
ErrDeviceCode,
ErrClientCredentials,
ErrTimeout,
ErrCallbackServer,
ErrTokenPersist,
ErrOIDCConfig,
}
for _, sentinel := range sentinels {
assert.True(t, errors.Is(sentinel, sentinel),
"expected %v to match itself", sentinel)
}
}
func TestSentinelErrors_WrappedMatchViIs(t *testing.T) {
cases := []struct {
name string
sentinel error
}{
{"ErrDiscovery", ErrDiscovery},
{"ErrAuthCode", ErrAuthCode},
{"ErrDeviceCode", ErrDeviceCode},
{"ErrClientCredentials", ErrClientCredentials},
{"ErrTimeout", ErrTimeout},
{"ErrCallbackServer", ErrCallbackServer},
{"ErrTokenPersist", ErrTokenPersist},
{"ErrOIDCConfig", ErrOIDCConfig},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
wrapped := fmt.Errorf("operation failed: %w", tc.sentinel)
assert.True(t, errors.Is(wrapped, tc.sentinel),
"wrapped error should match sentinel via errors.Is")
})
}
}
func TestSentinelErrors_HaveDescriptiveMessages(t *testing.T) {
cases := []struct {
sentinel error
contains string
}{
{ErrDiscovery, "discovery"},
{ErrAuthCode, "auth code"},
{ErrDeviceCode, "device code"},
{ErrClientCredentials, "client credentials"},
{ErrTimeout, "timed out"},
{ErrCallbackServer, "callback server"},
{ErrTokenPersist, "token persistence"},
{ErrOIDCConfig, "OIDC config"},
}
for _, tc := range cases {
t.Run(tc.sentinel.Error(), func(t *testing.T) {
assert.Contains(t, tc.sentinel.Error(), tc.contains)
})
}
}
func TestSentinelErrors_DoubleWrapped(t *testing.T) {
inner := fmt.Errorf("http timeout: %w", ErrDiscovery)
outer := fmt.Errorf("login failed: %w", inner)
assert.True(t, errors.Is(outer, ErrDiscovery),
"double-wrapped error should still match sentinel")
}