mirror of
https://github.com/juanfont/headscale.git
synced 2024-12-20 19:09:07 +01:00
218138afee
expand user, add claims to user This commit expands the user table with additional fields that can be retrieved from OIDC providers (and other places) and uses this data in various tailscale response objects if it is available. This is the beginning of implementing https://docs.google.com/document/d/1X85PMxIaVWDF6T_UPji3OeeUqVBcGj_uHRM5CI-AwlY/edit trying to make OIDC more coherant and maintainable in addition to giving the user a better experience and integration with a provider. remove usernames in magic dns, normalisation of emails this commit removes the option to have usernames as part of MagicDNS domains and headscale will now align with Tailscale, where there is a root domain, and the machine name. In addition, the various normalisation functions for dns names has been made lighter not caring about username and special character that wont occur. Email are no longer normalised as part of the policy processing. untagle oidc and regcache, use typed cache This commits stops reusing the registration cache for oidc purposes and switches the cache to be types and not use any allowing the removal of a bunch of casting. try to make reauth/register branches clearer in oidc Currently there was a function that did a bunch of stuff, finding the machine key, trying to find the node, reauthing the node, returning some status, and it was called validate which was very confusing. This commit tries to split this into what to do if the node exists, if it needs to register etc. Signed-off-by: Kristoffer Dalby <kristoffer@tailscale.com>
141 lines
2.9 KiB
Go
141 lines
2.9 KiB
Go
package util
|
|
|
|
import (
|
|
"net/netip"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestCheckForFQDNRules(t *testing.T) {
|
|
type args struct {
|
|
name string
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
wantErr bool
|
|
}{
|
|
{
|
|
name: "valid: user",
|
|
args: args{name: "valid-user"},
|
|
wantErr: false,
|
|
},
|
|
{
|
|
name: "invalid: capitalized user",
|
|
args: args{name: "Invalid-CapItaLIzed-user"},
|
|
wantErr: true,
|
|
},
|
|
{
|
|
name: "invalid: email as user",
|
|
args: args{name: "foo.bar@example.com"},
|
|
wantErr: true,
|
|
},
|
|
{
|
|
name: "invalid: chars in user name",
|
|
args: args{name: "super-user+name"},
|
|
wantErr: true,
|
|
},
|
|
{
|
|
name: "invalid: too long name for user",
|
|
args: args{
|
|
name: "super-long-useruseruser-name-that-should-be-a-little-more-than-63-chars",
|
|
},
|
|
wantErr: true,
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
if err := CheckForFQDNRules(tt.args.name); (err != nil) != tt.wantErr {
|
|
t.Errorf("CheckForFQDNRules() error = %v, wantErr %v", err, tt.wantErr)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestMagicDNSRootDomains100(t *testing.T) {
|
|
domains := GenerateIPv4DNSRootDomain(netip.MustParsePrefix("100.64.0.0/10"))
|
|
|
|
found := false
|
|
for _, domain := range domains {
|
|
if domain == "64.100.in-addr.arpa." {
|
|
found = true
|
|
|
|
break
|
|
}
|
|
}
|
|
assert.True(t, found)
|
|
|
|
found = false
|
|
for _, domain := range domains {
|
|
if domain == "100.100.in-addr.arpa." {
|
|
found = true
|
|
|
|
break
|
|
}
|
|
}
|
|
assert.True(t, found)
|
|
|
|
found = false
|
|
for _, domain := range domains {
|
|
if domain == "127.100.in-addr.arpa." {
|
|
found = true
|
|
|
|
break
|
|
}
|
|
}
|
|
assert.True(t, found)
|
|
}
|
|
|
|
func TestMagicDNSRootDomains172(t *testing.T) {
|
|
domains := GenerateIPv4DNSRootDomain(netip.MustParsePrefix("172.16.0.0/16"))
|
|
|
|
found := false
|
|
for _, domain := range domains {
|
|
if domain == "0.16.172.in-addr.arpa." {
|
|
found = true
|
|
|
|
break
|
|
}
|
|
}
|
|
assert.True(t, found)
|
|
|
|
found = false
|
|
for _, domain := range domains {
|
|
if domain == "255.16.172.in-addr.arpa." {
|
|
found = true
|
|
|
|
break
|
|
}
|
|
}
|
|
assert.True(t, found)
|
|
}
|
|
|
|
// Happens when netmask is a multiple of 4 bits (sounds likely).
|
|
func TestMagicDNSRootDomainsIPv6Single(t *testing.T) {
|
|
domains := GenerateIPv6DNSRootDomain(netip.MustParsePrefix("fd7a:115c:a1e0::/48"))
|
|
|
|
assert.Len(t, domains, 1)
|
|
assert.Equal(t, "0.e.1.a.c.5.1.1.a.7.d.f.ip6.arpa.", domains[0].WithTrailingDot())
|
|
}
|
|
|
|
func TestMagicDNSRootDomainsIPv6SingleMultiple(t *testing.T) {
|
|
domains := GenerateIPv6DNSRootDomain(netip.MustParsePrefix("fd7a:115c:a1e0::/50"))
|
|
|
|
yieldsRoot := func(dom string) bool {
|
|
for _, candidate := range domains {
|
|
if candidate.WithTrailingDot() == dom {
|
|
return true
|
|
}
|
|
}
|
|
|
|
return false
|
|
}
|
|
|
|
assert.Len(t, domains, 4)
|
|
assert.True(t, yieldsRoot("0.0.e.1.a.c.5.1.1.a.7.d.f.ip6.arpa."))
|
|
assert.True(t, yieldsRoot("1.0.e.1.a.c.5.1.1.a.7.d.f.ip6.arpa."))
|
|
assert.True(t, yieldsRoot("2.0.e.1.a.c.5.1.1.a.7.d.f.ip6.arpa."))
|
|
assert.True(t, yieldsRoot("3.0.e.1.a.c.5.1.1.a.7.d.f.ip6.arpa."))
|
|
}
|