mirror of
https://github.com/tailscale/tailscale.git
synced 2025-04-24 01:41:42 +00:00
cmd/tsidp: fix interface{} linter warnings (#15729)
Replace all instances of interface{} with any to resolve the golangci-lint errors that appeared in the previous tsidp PR. Updates #cleanup Signed-off-by: Patrick O'Doherty <patrick@tailscale.com>
This commit is contained in:
parent
b34a2bdb22
commit
e649227ef2
@ -544,13 +544,13 @@ type userInfo struct {
|
|||||||
|
|
||||||
type capRule struct {
|
type capRule struct {
|
||||||
IncludeInUserInfo bool `json:"includeInUserInfo"`
|
IncludeInUserInfo bool `json:"includeInUserInfo"`
|
||||||
ExtraClaims map[string]interface{} `json:"extraClaims,omitempty"` // list of features peer is allowed to edit
|
ExtraClaims map[string]any `json:"extraClaims,omitempty"` // list of features peer is allowed to edit
|
||||||
}
|
}
|
||||||
|
|
||||||
// flattenExtraClaims merges all ExtraClaims from a slice of capRule into a single map.
|
// flattenExtraClaims merges all ExtraClaims from a slice of capRule into a single map.
|
||||||
// It deduplicates values for each claim and preserves the original input type:
|
// It deduplicates values for each claim and preserves the original input type:
|
||||||
// scalar values remain scalars, and slices are returned as deduplicated []interface{} slices.
|
// scalar values remain scalars, and slices are returned as deduplicated []any slices.
|
||||||
func flattenExtraClaims(rules []capRule) map[string]interface{} {
|
func flattenExtraClaims(rules []capRule) map[string]any {
|
||||||
// sets stores deduplicated stringified values for each claim key.
|
// sets stores deduplicated stringified values for each claim key.
|
||||||
sets := make(map[string]map[string]struct{})
|
sets := make(map[string]map[string]struct{})
|
||||||
|
|
||||||
@ -561,7 +561,7 @@ func flattenExtraClaims(rules []capRule) map[string]interface{} {
|
|||||||
for claim, raw := range rule.ExtraClaims {
|
for claim, raw := range rule.ExtraClaims {
|
||||||
// Track whether the claim was provided as a slice
|
// Track whether the claim was provided as a slice
|
||||||
switch raw.(type) {
|
switch raw.(type) {
|
||||||
case []string, []interface{}:
|
case []string, []any:
|
||||||
isSlice[claim] = true
|
isSlice[claim] = true
|
||||||
default:
|
default:
|
||||||
// Only mark as scalar if this is the first time we've seen this claim
|
// Only mark as scalar if this is the first time we've seen this claim
|
||||||
@ -576,11 +576,11 @@ func flattenExtraClaims(rules []capRule) map[string]interface{} {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Build final result: either scalar or slice depending on original type
|
// Build final result: either scalar or slice depending on original type
|
||||||
result := make(map[string]interface{})
|
result := make(map[string]any)
|
||||||
for claim, valSet := range sets {
|
for claim, valSet := range sets {
|
||||||
if isSlice[claim] {
|
if isSlice[claim] {
|
||||||
// Claim was provided as a slice: output as []interface{}
|
// Claim was provided as a slice: output as []any
|
||||||
var vals []interface{}
|
var vals []any
|
||||||
for val := range valSet {
|
for val := range valSet {
|
||||||
vals = append(vals, val)
|
vals = append(vals, val)
|
||||||
}
|
}
|
||||||
@ -600,7 +600,7 @@ func flattenExtraClaims(rules []capRule) map[string]interface{} {
|
|||||||
// addClaimValue adds a claim value to the deduplication set for a given claim key.
|
// addClaimValue adds a claim value to the deduplication set for a given claim key.
|
||||||
// It accepts scalars (string, int, float64), slices of strings or interfaces,
|
// It accepts scalars (string, int, float64), slices of strings or interfaces,
|
||||||
// and recursively handles nested slices. Unsupported types are ignored with a log message.
|
// and recursively handles nested slices. Unsupported types are ignored with a log message.
|
||||||
func addClaimValue(sets map[string]map[string]struct{}, claim string, val interface{}) {
|
func addClaimValue(sets map[string]map[string]struct{}, claim string, val any) {
|
||||||
switch v := val.(type) {
|
switch v := val.(type) {
|
||||||
case string, float64, int, int64:
|
case string, float64, int, int64:
|
||||||
// Ensure the claim set is initialized
|
// Ensure the claim set is initialized
|
||||||
@ -620,7 +620,7 @@ func addClaimValue(sets map[string]map[string]struct{}, claim string, val interf
|
|||||||
sets[claim][s] = struct{}{}
|
sets[claim][s] = struct{}{}
|
||||||
}
|
}
|
||||||
|
|
||||||
case []interface{}:
|
case []any:
|
||||||
// Recursively handle each item in the slice
|
// Recursively handle each item in the slice
|
||||||
for _, item := range v {
|
for _, item := range v {
|
||||||
addClaimValue(sets, claim, item)
|
addClaimValue(sets, claim, item)
|
||||||
@ -633,7 +633,7 @@ func addClaimValue(sets map[string]map[string]struct{}, claim string, val interf
|
|||||||
}
|
}
|
||||||
|
|
||||||
// withExtraClaims merges flattened extra claims from a list of capRule into the provided struct v,
|
// withExtraClaims merges flattened extra claims from a list of capRule into the provided struct v,
|
||||||
// returning a map[string]interface{} that combines both sources.
|
// returning a map[string]any that combines both sources.
|
||||||
//
|
//
|
||||||
// v is any struct whose fields represent static claims; it is first marshaled to JSON, then unmarshalled into a generic map.
|
// v is any struct whose fields represent static claims; it is first marshaled to JSON, then unmarshalled into a generic map.
|
||||||
// rules is a slice of capRule objects that may define additional (extra) claims to merge.
|
// rules is a slice of capRule objects that may define additional (extra) claims to merge.
|
||||||
@ -643,7 +643,7 @@ func addClaimValue(sets map[string]map[string]struct{}, claim string, val interf
|
|||||||
// If an extra claim attempts to overwrite a protected claim, an error is returned.
|
// If an extra claim attempts to overwrite a protected claim, an error is returned.
|
||||||
//
|
//
|
||||||
// Returns the merged claims map or an error if any protected claim is violated or JSON (un)marshaling fails.
|
// Returns the merged claims map or an error if any protected claim is violated or JSON (un)marshaling fails.
|
||||||
func withExtraClaims(v any, rules []capRule) (map[string]interface{}, error) {
|
func withExtraClaims(v any, rules []capRule) (map[string]any, error) {
|
||||||
// Marshal the static struct
|
// Marshal the static struct
|
||||||
data, err := json.Marshal(v)
|
data, err := json.Marshal(v)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -651,7 +651,7 @@ func withExtraClaims(v any, rules []capRule) (map[string]interface{}, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Unmarshal into a generic map
|
// Unmarshal into a generic map
|
||||||
var claimMap map[string]interface{}
|
var claimMap map[string]any
|
||||||
if err := json.Unmarshal(data, &claimMap); err != nil {
|
if err := json.Unmarshal(data, &claimMap); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -7,8 +7,6 @@ import (
|
|||||||
"crypto/rsa"
|
"crypto/rsa"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"gopkg.in/square/go-jose.v2"
|
|
||||||
"gopkg.in/square/go-jose.v2/jwt"
|
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -18,29 +16,32 @@ import (
|
|||||||
"reflect"
|
"reflect"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"gopkg.in/square/go-jose.v2"
|
||||||
|
"gopkg.in/square/go-jose.v2/jwt"
|
||||||
"tailscale.com/client/tailscale/apitype"
|
"tailscale.com/client/tailscale/apitype"
|
||||||
"tailscale.com/tailcfg"
|
"tailscale.com/tailcfg"
|
||||||
"tailscale.com/types/key"
|
"tailscale.com/types/key"
|
||||||
"tailscale.com/types/views"
|
"tailscale.com/types/views"
|
||||||
"testing"
|
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// normalizeMap recursively sorts []interface{} values in a map[string]interface{}
|
// normalizeMap recursively sorts []any values in a map[string]any
|
||||||
func normalizeMap(t *testing.T, m map[string]interface{}) map[string]interface{} {
|
func normalizeMap(t *testing.T, m map[string]any) map[string]any {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
normalized := make(map[string]interface{}, len(m))
|
normalized := make(map[string]any, len(m))
|
||||||
for k, v := range m {
|
for k, v := range m {
|
||||||
switch val := v.(type) {
|
switch val := v.(type) {
|
||||||
case []interface{}:
|
case []any:
|
||||||
sorted := make([]string, len(val))
|
sorted := make([]string, len(val))
|
||||||
for i, item := range val {
|
for i, item := range val {
|
||||||
sorted[i] = fmt.Sprintf("%v", item) // convert everything to string for sorting
|
sorted[i] = fmt.Sprintf("%v", item) // convert everything to string for sorting
|
||||||
}
|
}
|
||||||
sort.Strings(sorted)
|
sort.Strings(sorted)
|
||||||
|
|
||||||
// convert back to []interface{}
|
// convert back to []any
|
||||||
sortedIface := make([]interface{}, len(sorted))
|
sortedIface := make([]any, len(sorted))
|
||||||
for i, s := range sorted {
|
for i, s := range sorted {
|
||||||
sortedIface[i] = s
|
sortedIface[i] = s
|
||||||
}
|
}
|
||||||
@ -101,26 +102,26 @@ func TestFlattenExtraClaims(t *testing.T) {
|
|||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
input []capRule
|
input []capRule
|
||||||
expected map[string]interface{}
|
expected map[string]any
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "empty extra claims",
|
name: "empty extra claims",
|
||||||
input: []capRule{
|
input: []capRule{
|
||||||
{ExtraClaims: map[string]interface{}{}},
|
{ExtraClaims: map[string]any{}},
|
||||||
},
|
},
|
||||||
expected: map[string]interface{}{},
|
expected: map[string]any{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "string and number values",
|
name: "string and number values",
|
||||||
input: []capRule{
|
input: []capRule{
|
||||||
{
|
{
|
||||||
ExtraClaims: map[string]interface{}{
|
ExtraClaims: map[string]any{
|
||||||
"featureA": "read",
|
"featureA": "read",
|
||||||
"featureB": 42,
|
"featureB": 42,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expected: map[string]interface{}{
|
expected: map[string]any{
|
||||||
"featureA": "read",
|
"featureA": "read",
|
||||||
"featureB": "42",
|
"featureB": "42",
|
||||||
},
|
},
|
||||||
@ -129,95 +130,95 @@ func TestFlattenExtraClaims(t *testing.T) {
|
|||||||
name: "slice of strings and ints",
|
name: "slice of strings and ints",
|
||||||
input: []capRule{
|
input: []capRule{
|
||||||
{
|
{
|
||||||
ExtraClaims: map[string]interface{}{
|
ExtraClaims: map[string]any{
|
||||||
"roles": []interface{}{"admin", "user", 1},
|
"roles": []any{"admin", "user", 1},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expected: map[string]interface{}{
|
expected: map[string]any{
|
||||||
"roles": []interface{}{"admin", "user", "1"},
|
"roles": []any{"admin", "user", "1"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "duplicate values deduplicated (slice input)",
|
name: "duplicate values deduplicated (slice input)",
|
||||||
input: []capRule{
|
input: []capRule{
|
||||||
{
|
{
|
||||||
ExtraClaims: map[string]interface{}{
|
ExtraClaims: map[string]any{
|
||||||
"foo": []string{"bar", "baz"},
|
"foo": []string{"bar", "baz"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ExtraClaims: map[string]interface{}{
|
ExtraClaims: map[string]any{
|
||||||
"foo": []interface{}{"bar", "qux"},
|
"foo": []any{"bar", "qux"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expected: map[string]interface{}{
|
expected: map[string]any{
|
||||||
"foo": []interface{}{"bar", "baz", "qux"},
|
"foo": []any{"bar", "baz", "qux"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "ignore unsupported map type, keep valid scalar",
|
name: "ignore unsupported map type, keep valid scalar",
|
||||||
input: []capRule{
|
input: []capRule{
|
||||||
{
|
{
|
||||||
ExtraClaims: map[string]interface{}{
|
ExtraClaims: map[string]any{
|
||||||
"invalid": map[string]interface{}{"bad": "yes"},
|
"invalid": map[string]any{"bad": "yes"},
|
||||||
"valid": "ok",
|
"valid": "ok",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expected: map[string]interface{}{
|
expected: map[string]any{
|
||||||
"valid": "ok",
|
"valid": "ok",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "scalar first, slice second",
|
name: "scalar first, slice second",
|
||||||
input: []capRule{
|
input: []capRule{
|
||||||
{ExtraClaims: map[string]interface{}{"foo": "bar"}},
|
{ExtraClaims: map[string]any{"foo": "bar"}},
|
||||||
{ExtraClaims: map[string]interface{}{"foo": []interface{}{"baz"}}},
|
{ExtraClaims: map[string]any{"foo": []any{"baz"}}},
|
||||||
},
|
},
|
||||||
expected: map[string]interface{}{
|
expected: map[string]any{
|
||||||
"foo": []interface{}{"bar", "baz"}, // since first was scalar, second being a slice forces slice output
|
"foo": []any{"bar", "baz"}, // since first was scalar, second being a slice forces slice output
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "conflicting scalar and unsupported map",
|
name: "conflicting scalar and unsupported map",
|
||||||
input: []capRule{
|
input: []capRule{
|
||||||
{ExtraClaims: map[string]interface{}{"foo": "bar"}},
|
{ExtraClaims: map[string]any{"foo": "bar"}},
|
||||||
{ExtraClaims: map[string]interface{}{"foo": map[string]interface{}{"bad": "entry"}}},
|
{ExtraClaims: map[string]any{"foo": map[string]any{"bad": "entry"}}},
|
||||||
},
|
},
|
||||||
expected: map[string]interface{}{
|
expected: map[string]any{
|
||||||
"foo": "bar", // map should be ignored
|
"foo": "bar", // map should be ignored
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "multiple slices with overlap",
|
name: "multiple slices with overlap",
|
||||||
input: []capRule{
|
input: []capRule{
|
||||||
{ExtraClaims: map[string]interface{}{"roles": []interface{}{"admin", "user"}}},
|
{ExtraClaims: map[string]any{"roles": []any{"admin", "user"}}},
|
||||||
{ExtraClaims: map[string]interface{}{"roles": []interface{}{"admin", "guest"}}},
|
{ExtraClaims: map[string]any{"roles": []any{"admin", "guest"}}},
|
||||||
},
|
},
|
||||||
expected: map[string]interface{}{
|
expected: map[string]any{
|
||||||
"roles": []interface{}{"admin", "user", "guest"},
|
"roles": []any{"admin", "user", "guest"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "slice with unsupported values",
|
name: "slice with unsupported values",
|
||||||
input: []capRule{
|
input: []capRule{
|
||||||
{ExtraClaims: map[string]interface{}{
|
{ExtraClaims: map[string]any{
|
||||||
"mixed": []interface{}{"ok", 42, map[string]string{"oops": "fail"}},
|
"mixed": []any{"ok", 42, map[string]string{"oops": "fail"}},
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
expected: map[string]interface{}{
|
expected: map[string]any{
|
||||||
"mixed": []interface{}{"ok", "42"}, // map is ignored
|
"mixed": []any{"ok", "42"}, // map is ignored
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "duplicate scalar value",
|
name: "duplicate scalar value",
|
||||||
input: []capRule{
|
input: []capRule{
|
||||||
{ExtraClaims: map[string]interface{}{"env": "prod"}},
|
{ExtraClaims: map[string]any{"env": "prod"}},
|
||||||
{ExtraClaims: map[string]interface{}{"env": "prod"}},
|
{ExtraClaims: map[string]any{"env": "prod"}},
|
||||||
},
|
},
|
||||||
expected: map[string]interface{}{
|
expected: map[string]any{
|
||||||
"env": "prod", // not converted to slice
|
"env": "prod", // not converted to slice
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -242,7 +243,7 @@ func TestExtraClaims(t *testing.T) {
|
|||||||
name string
|
name string
|
||||||
claim tailscaleClaims
|
claim tailscaleClaims
|
||||||
extraClaims []capRule
|
extraClaims []capRule
|
||||||
expected map[string]interface{}
|
expected map[string]any
|
||||||
expectError bool
|
expectError bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
@ -261,12 +262,12 @@ func TestExtraClaims(t *testing.T) {
|
|||||||
},
|
},
|
||||||
extraClaims: []capRule{
|
extraClaims: []capRule{
|
||||||
{
|
{
|
||||||
ExtraClaims: map[string]interface{}{
|
ExtraClaims: map[string]any{
|
||||||
"foo": []string{"bar"},
|
"foo": []string{"bar"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expected: map[string]interface{}{
|
expected: map[string]any{
|
||||||
"nonce": "foobar",
|
"nonce": "foobar",
|
||||||
"key": "nodekey:0000000000000000000000000000000000000000000000000000000000000000",
|
"key": "nodekey:0000000000000000000000000000000000000000000000000000000000000000",
|
||||||
"addresses": nil,
|
"addresses": nil,
|
||||||
@ -275,7 +276,7 @@ func TestExtraClaims(t *testing.T) {
|
|||||||
"tailnet": "test.ts.net",
|
"tailnet": "test.ts.net",
|
||||||
"email": "test@example.com",
|
"email": "test@example.com",
|
||||||
"username": "test",
|
"username": "test",
|
||||||
"foo": []interface{}{"bar"},
|
"foo": []any{"bar"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -294,17 +295,17 @@ func TestExtraClaims(t *testing.T) {
|
|||||||
},
|
},
|
||||||
extraClaims: []capRule{
|
extraClaims: []capRule{
|
||||||
{
|
{
|
||||||
ExtraClaims: map[string]interface{}{
|
ExtraClaims: map[string]any{
|
||||||
"foo": []string{"bar"},
|
"foo": []string{"bar"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ExtraClaims: map[string]interface{}{
|
ExtraClaims: map[string]any{
|
||||||
"foo": []string{"foobar"},
|
"foo": []string{"foobar"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expected: map[string]interface{}{
|
expected: map[string]any{
|
||||||
"nonce": "foobar",
|
"nonce": "foobar",
|
||||||
"key": "nodekey:0000000000000000000000000000000000000000000000000000000000000000",
|
"key": "nodekey:0000000000000000000000000000000000000000000000000000000000000000",
|
||||||
"addresses": nil,
|
"addresses": nil,
|
||||||
@ -313,7 +314,7 @@ func TestExtraClaims(t *testing.T) {
|
|||||||
"tailnet": "test.ts.net",
|
"tailnet": "test.ts.net",
|
||||||
"email": "test@example.com",
|
"email": "test@example.com",
|
||||||
"username": "test",
|
"username": "test",
|
||||||
"foo": []interface{}{"foobar", "bar"},
|
"foo": []any{"foobar", "bar"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -332,17 +333,17 @@ func TestExtraClaims(t *testing.T) {
|
|||||||
},
|
},
|
||||||
extraClaims: []capRule{
|
extraClaims: []capRule{
|
||||||
{
|
{
|
||||||
ExtraClaims: map[string]interface{}{
|
ExtraClaims: map[string]any{
|
||||||
"foo": []string{"bar"},
|
"foo": []string{"bar"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ExtraClaims: map[string]interface{}{
|
ExtraClaims: map[string]any{
|
||||||
"bar": []string{"foo"},
|
"bar": []string{"foo"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expected: map[string]interface{}{
|
expected: map[string]any{
|
||||||
"nonce": "foobar",
|
"nonce": "foobar",
|
||||||
"key": "nodekey:0000000000000000000000000000000000000000000000000000000000000000",
|
"key": "nodekey:0000000000000000000000000000000000000000000000000000000000000000",
|
||||||
"addresses": nil,
|
"addresses": nil,
|
||||||
@ -351,8 +352,8 @@ func TestExtraClaims(t *testing.T) {
|
|||||||
"tailnet": "test.ts.net",
|
"tailnet": "test.ts.net",
|
||||||
"email": "test@example.com",
|
"email": "test@example.com",
|
||||||
"username": "test",
|
"username": "test",
|
||||||
"foo": []interface{}{"bar"},
|
"foo": []any{"bar"},
|
||||||
"bar": []interface{}{"foo"},
|
"bar": []any{"foo"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -371,12 +372,12 @@ func TestExtraClaims(t *testing.T) {
|
|||||||
},
|
},
|
||||||
extraClaims: []capRule{
|
extraClaims: []capRule{
|
||||||
{
|
{
|
||||||
ExtraClaims: map[string]interface{}{
|
ExtraClaims: map[string]any{
|
||||||
"username": "foobar",
|
"username": "foobar",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expected: map[string]interface{}{
|
expected: map[string]any{
|
||||||
"nonce": "foobar",
|
"nonce": "foobar",
|
||||||
"key": "nodekey:0000000000000000000000000000000000000000000000000000000000000000",
|
"key": "nodekey:0000000000000000000000000000000000000000000000000000000000000000",
|
||||||
"addresses": nil,
|
"addresses": nil,
|
||||||
@ -402,8 +403,8 @@ func TestExtraClaims(t *testing.T) {
|
|||||||
UserID: 0,
|
UserID: 0,
|
||||||
UserName: "test",
|
UserName: "test",
|
||||||
},
|
},
|
||||||
extraClaims: []capRule{{ExtraClaims: map[string]interface{}{}}},
|
extraClaims: []capRule{{ExtraClaims: map[string]any{}}},
|
||||||
expected: map[string]interface{}{
|
expected: map[string]any{
|
||||||
"nonce": "foobar",
|
"nonce": "foobar",
|
||||||
"key": "nodekey:0000000000000000000000000000000000000000000000000000000000000000",
|
"key": "nodekey:0000000000000000000000000000000000000000000000000000000000000000",
|
||||||
"addresses": nil,
|
"addresses": nil,
|
||||||
@ -427,13 +428,13 @@ func TestExtraClaims(t *testing.T) {
|
|||||||
return // just as expected
|
return // just as expected
|
||||||
}
|
}
|
||||||
|
|
||||||
// Marshal to JSON then unmarshal back to map[string]interface{}
|
// Marshal to JSON then unmarshal back to map[string]any
|
||||||
gotClaims, err := json.Marshal(claims)
|
gotClaims, err := json.Marshal(claims)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("json.Marshal(claims) error = %v", err)
|
t.Errorf("json.Marshal(claims) error = %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var gotClaimsMap map[string]interface{}
|
var gotClaimsMap map[string]any
|
||||||
if err := json.Unmarshal(gotClaims, &gotClaimsMap); err != nil {
|
if err := json.Unmarshal(gotClaims, &gotClaimsMap); err != nil {
|
||||||
t.Fatalf("json.Unmarshal(gotClaims) error = %v", err)
|
t.Fatalf("json.Unmarshal(gotClaims) error = %v", err)
|
||||||
}
|
}
|
||||||
@ -459,7 +460,7 @@ func TestServeToken(t *testing.T) {
|
|||||||
redirectURI string
|
redirectURI string
|
||||||
remoteAddr string
|
remoteAddr string
|
||||||
expectError bool
|
expectError bool
|
||||||
expected map[string]interface{}
|
expected map[string]any
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "GET not allowed",
|
name: "GET not allowed",
|
||||||
@ -516,13 +517,13 @@ func TestServeToken(t *testing.T) {
|
|||||||
tailcfg.PeerCapabilityTsIDP: {
|
tailcfg.PeerCapabilityTsIDP: {
|
||||||
mustMarshalJSON(t, capRule{
|
mustMarshalJSON(t, capRule{
|
||||||
IncludeInUserInfo: true,
|
IncludeInUserInfo: true,
|
||||||
ExtraClaims: map[string]interface{}{
|
ExtraClaims: map[string]any{
|
||||||
"foo": "bar",
|
"foo": "bar",
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expected: map[string]interface{}{
|
expected: map[string]any{
|
||||||
"foo": "bar",
|
"foo": "bar",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -536,7 +537,7 @@ func TestServeToken(t *testing.T) {
|
|||||||
tailcfg.PeerCapabilityTsIDP: {
|
tailcfg.PeerCapabilityTsIDP: {
|
||||||
mustMarshalJSON(t, capRule{
|
mustMarshalJSON(t, capRule{
|
||||||
IncludeInUserInfo: true,
|
IncludeInUserInfo: true,
|
||||||
ExtraClaims: map[string]interface{}{
|
ExtraClaims: map[string]any{
|
||||||
"sub": "should-not-overwrite",
|
"sub": "should-not-overwrite",
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
@ -623,7 +624,7 @@ func TestServeToken(t *testing.T) {
|
|||||||
t.Fatalf("failed to parse ID token: %v", err)
|
t.Fatalf("failed to parse ID token: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
out := make(map[string]interface{})
|
out := make(map[string]any)
|
||||||
if err := tok.Claims(oidcTestingPublicKey(t), &out); err != nil {
|
if err := tok.Claims(oidcTestingPublicKey(t), &out); err != nil {
|
||||||
t.Fatalf("failed to extract claims: %v", err)
|
t.Fatalf("failed to extract claims: %v", err)
|
||||||
}
|
}
|
||||||
@ -647,7 +648,7 @@ func TestExtraUserInfo(t *testing.T) {
|
|||||||
name string
|
name string
|
||||||
caps tailcfg.PeerCapMap
|
caps tailcfg.PeerCapMap
|
||||||
tokenValidTill time.Time
|
tokenValidTill time.Time
|
||||||
expected map[string]interface{}
|
expected map[string]any
|
||||||
expectError bool
|
expectError bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
@ -657,14 +658,14 @@ func TestExtraUserInfo(t *testing.T) {
|
|||||||
tailcfg.PeerCapabilityTsIDP: {
|
tailcfg.PeerCapabilityTsIDP: {
|
||||||
mustMarshalJSON(t, capRule{
|
mustMarshalJSON(t, capRule{
|
||||||
IncludeInUserInfo: true,
|
IncludeInUserInfo: true,
|
||||||
ExtraClaims: map[string]interface{}{
|
ExtraClaims: map[string]any{
|
||||||
"foo": []string{"bar"},
|
"foo": []string{"bar"},
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expected: map[string]interface{}{
|
expected: map[string]any{
|
||||||
"foo": []interface{}{"bar"},
|
"foo": []any{"bar"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -674,14 +675,14 @@ func TestExtraUserInfo(t *testing.T) {
|
|||||||
tailcfg.PeerCapabilityTsIDP: {
|
tailcfg.PeerCapabilityTsIDP: {
|
||||||
mustMarshalJSON(t, capRule{
|
mustMarshalJSON(t, capRule{
|
||||||
IncludeInUserInfo: true,
|
IncludeInUserInfo: true,
|
||||||
ExtraClaims: map[string]interface{}{
|
ExtraClaims: map[string]any{
|
||||||
"foo": []string{"bar", "foobar"},
|
"foo": []string{"bar", "foobar"},
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expected: map[string]interface{}{
|
expected: map[string]any{
|
||||||
"foo": []interface{}{"bar", "foobar"},
|
"foo": []any{"bar", "foobar"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -691,14 +692,14 @@ func TestExtraUserInfo(t *testing.T) {
|
|||||||
tailcfg.PeerCapabilityTsIDP: {
|
tailcfg.PeerCapabilityTsIDP: {
|
||||||
mustMarshalJSON(t, capRule{
|
mustMarshalJSON(t, capRule{
|
||||||
IncludeInUserInfo: true,
|
IncludeInUserInfo: true,
|
||||||
ExtraClaims: map[string]interface{}{
|
ExtraClaims: map[string]any{
|
||||||
"foo": "bar",
|
"foo": "bar",
|
||||||
"bar": "foo",
|
"bar": "foo",
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expected: map[string]interface{}{
|
expected: map[string]any{
|
||||||
"foo": "bar",
|
"foo": "bar",
|
||||||
"bar": "foo",
|
"bar": "foo",
|
||||||
},
|
},
|
||||||
@ -707,7 +708,7 @@ func TestExtraUserInfo(t *testing.T) {
|
|||||||
name: "empty extra claims",
|
name: "empty extra claims",
|
||||||
caps: tailcfg.PeerCapMap{},
|
caps: tailcfg.PeerCapMap{},
|
||||||
tokenValidTill: time.Now().Add(1 * time.Minute),
|
tokenValidTill: time.Now().Add(1 * time.Minute),
|
||||||
expected: map[string]interface{}{},
|
expected: map[string]any{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "attempt to overwrite protected claim",
|
name: "attempt to overwrite protected claim",
|
||||||
@ -716,7 +717,7 @@ func TestExtraUserInfo(t *testing.T) {
|
|||||||
tailcfg.PeerCapabilityTsIDP: {
|
tailcfg.PeerCapabilityTsIDP: {
|
||||||
mustMarshalJSON(t, capRule{
|
mustMarshalJSON(t, capRule{
|
||||||
IncludeInUserInfo: true,
|
IncludeInUserInfo: true,
|
||||||
ExtraClaims: map[string]interface{}{
|
ExtraClaims: map[string]any{
|
||||||
"sub": "should-not-overwrite",
|
"sub": "should-not-overwrite",
|
||||||
"foo": "ok",
|
"foo": "ok",
|
||||||
},
|
},
|
||||||
@ -732,19 +733,19 @@ func TestExtraUserInfo(t *testing.T) {
|
|||||||
tailcfg.PeerCapabilityTsIDP: {
|
tailcfg.PeerCapabilityTsIDP: {
|
||||||
mustMarshalJSON(t, capRule{
|
mustMarshalJSON(t, capRule{
|
||||||
IncludeInUserInfo: false,
|
IncludeInUserInfo: false,
|
||||||
ExtraClaims: map[string]interface{}{
|
ExtraClaims: map[string]any{
|
||||||
"foo": "ok",
|
"foo": "ok",
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expected: map[string]interface{}{},
|
expected: map[string]any{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "expired token",
|
name: "expired token",
|
||||||
caps: tailcfg.PeerCapMap{},
|
caps: tailcfg.PeerCapMap{},
|
||||||
tokenValidTill: time.Now().Add(-1 * time.Minute),
|
tokenValidTill: time.Now().Add(-1 * time.Minute),
|
||||||
expected: map[string]interface{}{},
|
expected: map[string]any{},
|
||||||
expectError: true,
|
expectError: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -802,7 +803,7 @@ func TestExtraUserInfo(t *testing.T) {
|
|||||||
t.Fatalf("expected 200 OK, got %d: %s", rr.Code, rr.Body.String())
|
t.Fatalf("expected 200 OK, got %d: %s", rr.Code, rr.Body.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
var resp map[string]interface{}
|
var resp map[string]any
|
||||||
if err := json.Unmarshal(rr.Body.Bytes(), &resp); err != nil {
|
if err := json.Unmarshal(rr.Body.Bytes(), &resp); err != nil {
|
||||||
t.Fatalf("failed to parse JSON response: %v", err)
|
t.Fatalf("failed to parse JSON response: %v", err)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user