mirror of
https://github.com/steveiliop56/tinyauth.git
synced 2025-10-28 04:35:40 +00:00
refactor/handlers (#51)
* wip * refactor: use prefix instead of patern in docker meta * tests: fix tests
This commit is contained in:
@@ -46,14 +46,14 @@ func ParseUsers(users string) (types.Users, error) {
|
||||
return usersParsed, nil
|
||||
}
|
||||
|
||||
// Root url parses parses a hostname and returns the root domain (e.g. sub1.sub2.domain.com -> sub2.domain.com)
|
||||
func GetRootURL(urlSrc string) (string, error) {
|
||||
// Get upper domain parses a hostname and returns the upper domain (e.g. sub1.sub2.domain.com -> sub2.domain.com)
|
||||
func GetUpperDomain(urlSrc string) (string, error) {
|
||||
// Make sure the url is valid
|
||||
urlParsed, parseErr := url.Parse(urlSrc)
|
||||
urlParsed, err := url.Parse(urlSrc)
|
||||
|
||||
// Check if there was an error
|
||||
if parseErr != nil {
|
||||
return "", parseErr
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
// Split the hostname by period
|
||||
|
||||
@@ -38,15 +38,15 @@ func TestParseUsers(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// Test the get root url function
|
||||
func TestGetRootURL(t *testing.T) {
|
||||
t.Log("Testing get root url with a valid url")
|
||||
// Test the get upper domain function
|
||||
func TestGetUpperDomain(t *testing.T) {
|
||||
t.Log("Testing get upper domain with a valid url")
|
||||
|
||||
// Test the get root url function with a valid url
|
||||
// Test the get upper domain function with a valid url
|
||||
url := "https://sub1.sub2.domain.com:8080"
|
||||
expected := "sub2.domain.com"
|
||||
|
||||
result, err := utils.GetRootURL(url)
|
||||
result, err := utils.GetUpperDomain(url)
|
||||
|
||||
// Check if there was an error
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user