module main import alpm fn test_is_url() { for url in ['https://example.org/foo-1-1-any.pkg.tar.zst', 'http://x/y', 'ftp://x/y', 'file:///srv/pkgs/foo-1-1-any.pkg.tar.zst', 'ftps://x/y'] { assert is_url(url), url } for target in ['zsh', 'extra/zsh', './foo-1-1-any.pkg.tar.zst', '/tmp/foo.pkg.tar.zst', 'zsh>=5'] { assert !is_url(target), target } // the scheme is spelled as RFC 3986 says: a letter first, then letters, // digits and '.', '+' or '-', closed by '://'. a path with a stray '://' // in its name keeps being a path, and a text with '//' walk-in where a // scheme-opening should be keeps being one too assert is_url('a+b-c.d://host/x') // dots are legal letters of a scheme, so a dotted one is one ('file:', // 'ssh:' say it); a leading '-', an inner space or an opening digit do // not, and '://' without a scheme before it does not assert is_url('path.y.tar://') assert !is_url('-lead://host/x') assert !is_url('we ird://host/x') assert !is_url('://host/x') assert !is_url('9bad://host/x') } fn test_url_trust_warning() { url := 'https://example.org/foo-1-1-any.pkg.tar.zst' // no package check: the warning says so none_level := url_trust_warning(url, alpm.SigLevel.database) or { '' } assert none_level.contains('not checked') assert none_level.starts_with(url) // optional: the .sig is read when the server offers one, not otherwise optional := url_trust_warning(url, alpm.SigLevel.package | .package_optional) or { '' } assert optional.contains('only if the server offers one') // required: the load refuses an unsigned package, nothing to warn of if note := url_trust_warning(url, alpm.SigLevel.package) { assert false, 'a required signature was warned of: ${note}' } if note := url_trust_warning(url, alpm.SigLevel.package | .database) { assert false, 'a required signature was warned of: ${note}' } }