| 1 | module main |
| 2 | |
| 3 | import alpm |
| 4 | |
| 5 | fn test_is_url() { |
| 6 | for url in ['https://example.org/foo-1-1-any.pkg.tar.zst', 'http://x/y', 'ftp://x/y', |
| 7 | 'file:///srv/pkgs/foo-1-1-any.pkg.tar.zst', 'ftps://x/y'] { |
| 8 | assert is_url(url), url |
| 9 | } |
| 10 | for target in ['zsh', 'extra/zsh', './foo-1-1-any.pkg.tar.zst', '/tmp/foo.pkg.tar.zst', 'zsh>=5'] { |
| 11 | assert !is_url(target), target |
| 12 | } |
| 13 | // the scheme is spelled as RFC 3986 says: a letter first, then letters, |
| 14 | // digits and '.', '+' or '-', closed by '://'. a path with a stray '://' |
| 15 | // in its name keeps being a path, and a text with '//' walk-in where a |
| 16 | // scheme-opening should be keeps being one too |
| 17 | assert is_url('a+b-c.d://host/x') |
| 18 | // dots are legal letters of a scheme, so a dotted one is one ('file:', |
| 19 | // 'ssh:' say it); a leading '-', an inner space or an opening digit do |
| 20 | // not, and '://' without a scheme before it does not |
| 21 | assert is_url('path.y.tar://') |
| 22 | assert !is_url('-lead://host/x') |
| 23 | assert !is_url('we ird://host/x') |
| 24 | assert !is_url('://host/x') |
| 25 | assert !is_url('9bad://host/x') |
| 26 | } |
| 27 | |
| 28 | fn test_url_trust_warning() { |
| 29 | url := 'https://example.org/foo-1-1-any.pkg.tar.zst' |
| 30 | // no package check: the warning says so |
| 31 | none_level := url_trust_warning(url, alpm.SigLevel.database) or { '' } |
| 32 | assert none_level.contains('not checked') |
| 33 | assert none_level.starts_with(url) |
| 34 | // optional: the .sig is read when the server offers one, not otherwise |
| 35 | optional := url_trust_warning(url, alpm.SigLevel.package | .package_optional) or { '' } |
| 36 | assert optional.contains('only if the server offers one') |
| 37 | // required: the load refuses an unsigned package, nothing to warn of |
| 38 | if note := url_trust_warning(url, alpm.SigLevel.package) { |
| 39 | assert false, 'a required signature was warned of: ${note}' |
| 40 | } |
| 41 | if note := url_trust_warning(url, alpm.SigLevel.package | .database) { |
| 42 | assert false, 'a required signature was warned of: ${note}' |
| 43 | } |
| 44 | } |
| 45 | |