2021-09-17 04:44:35 +00:00
|
|
|
package ntp
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2022-03-02 06:40:26 +00:00
|
|
|
"time"
|
2021-09-17 04:44:35 +00:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
|
|
|
"github.com/authelia/authelia/v4/internal/configuration/schema"
|
|
|
|
"github.com/authelia/authelia/v4/internal/configuration/validator"
|
|
|
|
)
|
|
|
|
|
2023-01-03 22:12:19 +00:00
|
|
|
func TestShouldCheckNTPV4(t *testing.T) {
|
2022-02-28 03:15:01 +00:00
|
|
|
config := &schema.Configuration{
|
2023-01-26 02:23:47 +00:00
|
|
|
NTP: schema.NTP{
|
2023-05-07 06:39:17 +00:00
|
|
|
Address: &schema.AddressUDP{Address: schema.NewAddressFromNetworkValues(schema.AddressSchemeUDP, "time.cloudflare.com", 123)},
|
2022-03-02 06:40:26 +00:00
|
|
|
Version: 4,
|
|
|
|
MaximumDesync: time.Second * 3,
|
2022-02-28 03:15:01 +00:00
|
|
|
},
|
2021-09-17 04:44:35 +00:00
|
|
|
}
|
2022-02-28 03:15:01 +00:00
|
|
|
|
2021-09-17 04:44:35 +00:00
|
|
|
sv := schema.NewStructValidator()
|
2022-02-28 03:15:01 +00:00
|
|
|
validator.ValidateNTP(config, sv)
|
2021-09-17 04:44:35 +00:00
|
|
|
|
2022-03-02 06:40:26 +00:00
|
|
|
ntp := NewProvider(&config.NTP)
|
2021-09-17 04:44:35 +00:00
|
|
|
|
2021-11-23 09:45:38 +00:00
|
|
|
assert.NoError(t, ntp.StartupCheck())
|
2021-09-17 04:44:35 +00:00
|
|
|
}
|
2023-01-03 22:12:19 +00:00
|
|
|
|
|
|
|
func TestShouldCheckNTPV3(t *testing.T) {
|
|
|
|
config := &schema.Configuration{
|
2023-01-26 02:23:47 +00:00
|
|
|
NTP: schema.NTP{
|
2023-05-07 06:39:17 +00:00
|
|
|
Address: &schema.AddressUDP{Address: schema.NewAddressFromNetworkValues(schema.AddressSchemeUDP, "time.cloudflare.com", 123)},
|
2023-01-03 22:12:19 +00:00
|
|
|
Version: 3,
|
|
|
|
MaximumDesync: time.Second * 3,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
sv := schema.NewStructValidator()
|
|
|
|
validator.ValidateNTP(config, sv)
|
|
|
|
|
|
|
|
ntp := NewProvider(&config.NTP)
|
|
|
|
|
|
|
|
assert.NoError(t, ntp.StartupCheck())
|
|
|
|
}
|