Pull request: dhcpd: normalize client host
Updates #2946.
Squashed commit of the following:
commit f830c03ddee65f7e86c43baa00a7dcc022091d93
Merge: df6c83d7 327e76cd
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Tue Apr 13 15:55:58 2021 +0300
Merge branch 'master' into 2946-norm-dhcp-host
commit df6c83d7d117b718110a035216e708d5131bf71c
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Tue Apr 13 15:49:03 2021 +0300
dhcpd: imp docs
commit 1407e9bd7b7694bd3069349faba3ec9ff5eb468b
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Tue Apr 13 15:27:38 2021 +0300
dhcpd: normalize client host
This commit is contained in:
@@ -269,3 +269,56 @@ func TestV4DynamicLease_Get(t *testing.T) {
|
||||
assert.Equal(t, mac, ls[0].HWAddr)
|
||||
})
|
||||
}
|
||||
|
||||
func TestV4Server_normalizeHostname(t *testing.T) {
|
||||
testCases := []struct {
|
||||
name string
|
||||
hostname string
|
||||
wantErrMsg string
|
||||
want string
|
||||
}{{
|
||||
name: "success",
|
||||
hostname: "example.com",
|
||||
wantErrMsg: "",
|
||||
want: "example.com",
|
||||
}, {
|
||||
name: "success_empty",
|
||||
hostname: "",
|
||||
wantErrMsg: "",
|
||||
want: "",
|
||||
}, {
|
||||
name: "success_spaces",
|
||||
hostname: "my device 01",
|
||||
wantErrMsg: "",
|
||||
want: "my-device-01",
|
||||
}, {
|
||||
name: "error",
|
||||
hostname: "!!!",
|
||||
wantErrMsg: `validating non-normalized hostname: ` +
|
||||
`invalid domain name label at index 0: ` +
|
||||
`invalid char '!' at index 0 in "!!!"`,
|
||||
want: "",
|
||||
}, {
|
||||
name: "error_spaces",
|
||||
hostname: "! ! !",
|
||||
wantErrMsg: `validating normalized hostname: ` +
|
||||
`invalid domain name label at index 0: ` +
|
||||
`invalid char '!' at index 0 in "!-!-!"`,
|
||||
want: "",
|
||||
}}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
got, err := (&v4Server{}).normalizeHostname(tc.hostname)
|
||||
if tc.wantErrMsg == "" {
|
||||
assert.NoError(t, err)
|
||||
} else {
|
||||
require.Error(t, err)
|
||||
|
||||
assert.Equal(t, tc.wantErrMsg, err.Error())
|
||||
}
|
||||
|
||||
assert.Equal(t, tc.want, got)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user