(t *testing.T)
| 11 | ) |
| 12 | |
| 13 | func TestGetRootDomain(t *testing.T) { |
| 14 | // Normal case |
| 15 | domain := "http://sub.tinyauth.app" |
| 16 | expected := "tinyauth.app" |
| 17 | result, err := utils.GetCookieDomain(domain) |
| 18 | assert.NilError(t, err) |
| 19 | assert.Equal(t, expected, result) |
| 20 | |
| 21 | // Domain with multiple subdomains |
| 22 | domain = "http://b.c.tinyauth.app" |
| 23 | expected = "c.tinyauth.app" |
| 24 | result, err = utils.GetCookieDomain(domain) |
| 25 | assert.NilError(t, err) |
| 26 | assert.Equal(t, expected, result) |
| 27 | |
| 28 | // Invalid domain (only TLD) |
| 29 | domain = "com" |
| 30 | _, err = utils.GetCookieDomain(domain) |
| 31 | assert.ErrorContains(t, err, "invalid app url, must be at least second level domain") |
| 32 | |
| 33 | // IP address |
| 34 | domain = "http://10.10.10.10" |
| 35 | _, err = utils.GetCookieDomain(domain) |
| 36 | assert.ErrorContains(t, err, "IP addresses not allowed") |
| 37 | |
| 38 | // Invalid URL |
| 39 | domain = "http://[::1]:namedport" |
| 40 | _, err = utils.GetCookieDomain(domain) |
| 41 | assert.ErrorContains(t, err, "parse \"http://[::1]:namedport\": invalid port \":namedport\" after host") |
| 42 | |
| 43 | // URL with scheme and path |
| 44 | domain = "https://sub.tinyauth.app/path" |
| 45 | expected = "tinyauth.app" |
| 46 | result, err = utils.GetCookieDomain(domain) |
| 47 | assert.NilError(t, err) |
| 48 | assert.Equal(t, expected, result) |
| 49 | |
| 50 | // URL with port |
| 51 | domain = "http://sub.tinyauth.app:8080" |
| 52 | expected = "tinyauth.app" |
| 53 | result, err = utils.GetCookieDomain(domain) |
| 54 | assert.NilError(t, err) |
| 55 | assert.Equal(t, expected, result) |
| 56 | |
| 57 | // Domain managed by ICANN |
| 58 | domain = "http://example.co.uk" |
| 59 | _, err = utils.GetCookieDomain(domain) |
| 60 | assert.Error(t, err, "domain in public suffix list, cannot set cookies") |
| 61 | } |
| 62 | |
| 63 | func TestParseFileToLine(t *testing.T) { |
| 64 | // Normal case |
nothing calls this directly
no test coverage detected