347 lines
8.3 KiB
Bash
347 lines
8.3 KiB
Bash
#!/usr/bin/env bats
|
|
|
|
# parse_uri() from lib/uri.sh tests.
|
|
# See: https://bats-core.readthedocs.io/en/latest/index.html
|
|
|
|
setup() {
|
|
# Bats setup
|
|
load 'helpers/bats-support/load'
|
|
load 'helpers/bats-assert/load'
|
|
DIR="$( cd "$( dirname "$BATS_TEST_FILENAME" )" >/dev/null 2>&1 && pwd )"
|
|
PATH="$DIR/../src/lib:$PATH"
|
|
}
|
|
|
|
# ------------------------------ #
|
|
# Do tests! #
|
|
# ------------------------------ #
|
|
|
|
@test "file:/" {
|
|
. uri.sh
|
|
parse_uri 'file:/'
|
|
[ "$scheme" == 'file' ]
|
|
[ "$hostname" == '' ]
|
|
[ "$port" == '' ]
|
|
[ "$path" == '/' ]
|
|
[ "$username" == '' ]
|
|
[ "$password" == '' ]
|
|
[ "$query" == '' ]
|
|
[ "$fragment" == '' ]
|
|
}
|
|
|
|
@test "file:/path" {
|
|
. uri.sh
|
|
parse_uri 'file:/path'
|
|
[ "$scheme" == 'file' ]
|
|
[ "$hostname" == '' ]
|
|
[ "$port" == '' ]
|
|
[ "$path" == '/path' ]
|
|
[ "$username" == '' ]
|
|
[ "$password" == '' ]
|
|
[ "$query" == '' ]
|
|
[ "$fragment" == '' ]
|
|
}
|
|
|
|
@test "file:///" {
|
|
. uri.sh
|
|
parse_uri 'file:///'
|
|
[ "$scheme" == 'file' ]
|
|
[ "$hostname" == '' ]
|
|
[ "$port" == '' ]
|
|
[ "$path" == '/' ]
|
|
[ "$username" == '' ]
|
|
[ "$password" == '' ]
|
|
[ "$query" == '' ]
|
|
[ "$fragment" == '' ]
|
|
}
|
|
|
|
@test "file:///path/with/may/sub/dir/s" {
|
|
. uri.sh
|
|
parse_uri 'file:///path/with/may/sub/dir/s'
|
|
[ "$scheme" == 'file' ]
|
|
[ "$hostname" == '' ]
|
|
[ "$port" == '' ]
|
|
[ "$path" == '/path/with/may/sub/dir/s' ]
|
|
[ "$username" == '' ]
|
|
[ "$password" == '' ]
|
|
[ "$query" == '' ]
|
|
[ "$fragment" == '' ]
|
|
}
|
|
|
|
@test "." {
|
|
. uri.sh
|
|
parse_uri '.'
|
|
[ "$scheme" == 'file' ]
|
|
[ "$hostname" == '' ]
|
|
[ "$port" == '' ]
|
|
[ "$path" == '.' ]
|
|
[ "$username" == '' ]
|
|
[ "$password" == '' ]
|
|
[ "$query" == '' ]
|
|
[ "$fragment" == '' ]
|
|
}
|
|
|
|
@test "./relative/path" {
|
|
. uri.sh
|
|
parse_uri './relative/path'
|
|
[ "$scheme" == 'file' ]
|
|
[ "$hostname" == '' ]
|
|
[ "$port" == '' ]
|
|
[ "$path" == './relative/path' ]
|
|
[ "$username" == '' ]
|
|
[ "$password" == '' ]
|
|
[ "$query" == '' ]
|
|
[ "$fragment" == '' ]
|
|
}
|
|
|
|
@test "../relative/path" {
|
|
. uri.sh
|
|
parse_uri '../relative/path'
|
|
[ "$scheme" == 'file' ]
|
|
[ "$hostname" == '' ]
|
|
[ "$port" == '' ]
|
|
[ "$path" == '../relative/path' ]
|
|
[ "$username" == '' ]
|
|
[ "$password" == '' ]
|
|
[ "$query" == '' ]
|
|
[ "$fragment" == '' ]
|
|
}
|
|
|
|
@test "/abs/path" {
|
|
. uri.sh
|
|
parse_uri '/abs/path'
|
|
[ "$scheme" == 'file' ]
|
|
[ "$hostname" == '' ]
|
|
[ "$port" == '' ]
|
|
[ "$path" == '/abs/path' ]
|
|
[ "$username" == '' ]
|
|
[ "$password" == '' ]
|
|
[ "$query" == '' ]
|
|
[ "$fragment" == '' ]
|
|
}
|
|
|
|
@test "sqlite:///database.db" {
|
|
. uri.sh
|
|
parse_uri 'sqlite:///database.db'
|
|
[ "$scheme" == 'sqlite' ]
|
|
[ "$hostname" == '' ]
|
|
[ "$port" == '' ]
|
|
[ "$path" == '/database.db' ]
|
|
[ "$username" == '' ]
|
|
[ "$password" == '' ]
|
|
[ "$query" == '' ]
|
|
[ "$fragment" == '' ]
|
|
}
|
|
|
|
@test "file://host" {
|
|
. uri.sh
|
|
parse_uri 'file://host'
|
|
[ "$scheme" == 'file' ]
|
|
[ "$hostname" == 'host' ]
|
|
[ "$port" == '' ]
|
|
[ "$path" == '' ]
|
|
[ "$username" == '' ]
|
|
[ "$password" == '' ]
|
|
[ "$query" == '' ]
|
|
[ "$fragment" == '' ]
|
|
}
|
|
|
|
@test "s3://bucket/backups" {
|
|
. uri.sh
|
|
parse_uri 's3://bucket/backups'
|
|
[ "$scheme" == 's3' ]
|
|
[ "$hostname" == 'bucket' ]
|
|
[ "$port" == '' ]
|
|
[ "$path" == '/backups' ]
|
|
[ "$username" == '' ]
|
|
[ "$password" == '' ]
|
|
[ "$query" == '' ]
|
|
[ "$fragment" == '' ]
|
|
}
|
|
|
|
@test "dav://user@host/" {
|
|
. uri.sh
|
|
parse_uri 'dav://user@host/'
|
|
[ "$scheme" == 'dav' ]
|
|
[ "$hostname" == 'host' ]
|
|
[ "$port" == '' ]
|
|
[ "$path" == '/' ]
|
|
[ "$username" == 'user' ]
|
|
[ "$password" == '' ]
|
|
[ "$query" == '' ]
|
|
[ "$fragment" == '' ]
|
|
}
|
|
|
|
@test "dav://user:p%40%24%24w0rD@host/path/" {
|
|
. uri.sh
|
|
parse_uri 'dav://user:p%40%24%24w0rD@host/path/'
|
|
[ "$scheme" == 'dav' ]
|
|
[ "$hostname" == 'host' ]
|
|
[ "$port" == '' ]
|
|
[ "$path" == '/path/' ]
|
|
[ "$username" == 'user' ]
|
|
[ "$password" == 'p@$$w0rD' ]
|
|
[ "$query" == '' ]
|
|
[ "$fragment" == '' ]
|
|
}
|
|
|
|
@test "rsync://user:password@host:/p/a/th" {
|
|
. uri.sh
|
|
parse_uri 'rsync://user:password@host:/p/a/th'
|
|
[ "$scheme" == 'rsync' ]
|
|
[ "$hostname" == 'host' ]
|
|
[ "$port" == '' ]
|
|
[ "$path" == '/p/a/th' ]
|
|
[ "$username" == 'user' ]
|
|
[ "$password" == 'password' ]
|
|
[ "$query" == '' ]
|
|
[ "$fragment" == '' ]
|
|
}
|
|
|
|
@test "rsync://user:password@host:~/backups" {
|
|
. uri.sh
|
|
parse_uri 'rsync://user:password@host:~/backups'
|
|
[ "$scheme" == 'rsync' ]
|
|
[ "$hostname" == 'host' ]
|
|
[ "$port" == '' ]
|
|
[ "$path" == '~/backups' ]
|
|
[ "$username" == 'user' ]
|
|
[ "$password" == 'password' ]
|
|
[ "$query" == '' ]
|
|
[ "$fragment" == '' ]
|
|
}
|
|
|
|
@test "postgres://user:password@host:5432" {
|
|
. uri.sh
|
|
parse_uri 'postgres://user:password@host:5432'
|
|
[ "$scheme" == 'postgres' ]
|
|
[ "$hostname" == 'host' ]
|
|
[ "$port" == '5432' ]
|
|
[ "$path" == '' ]
|
|
[ "$username" == 'user' ]
|
|
[ "$password" == 'password' ]
|
|
[ "$query" == '' ]
|
|
[ "$fragment" == '' ]
|
|
}
|
|
|
|
@test "http://user:password@host:port/path?q=val" {
|
|
. uri.sh
|
|
parse_uri 'scheme://user:password@host:123/path?q=val'
|
|
[ "$scheme" == 'scheme' ]
|
|
[ "$hostname" == 'host' ]
|
|
[ "$port" == '123' ]
|
|
[ "$path" == '/path' ]
|
|
[ "$username" == 'user' ]
|
|
[ "$password" == 'password' ]
|
|
[ "$query" == 'q=val' ]
|
|
[ "$fragment" == '' ]
|
|
}
|
|
|
|
@test "ftp://user:%24t%D0%AFo%7C%5C%7C6@[fe80::5054:ff:fe24:382]:2021/srv/" {
|
|
. uri.sh
|
|
parse_uri 'ftp://user:%24t%D0%AFo%7C%5C%7C6@[fe80::5054:ff:fe24:382]:2021/srv/'
|
|
[ "$scheme" == 'ftp' ]
|
|
[ "$hostname" == '[fe80::5054:ff:fe24:382]' ]
|
|
[ "$port" == '2021' ]
|
|
[ "$path" == '/srv/' ]
|
|
[ "$username" == 'user' ]
|
|
[ "$password" == '$tЯo|\|6' ]
|
|
[ "$query" == '' ]
|
|
[ "$fragment" == '' ]
|
|
}
|
|
|
|
# ------------------------------ #
|
|
# Test RFC 3986 Examples #
|
|
# ------------------------------ #
|
|
|
|
@test "https://john.doe@www.example.com:123/forum/questions/?tag=networking&order=newest#top" {
|
|
. uri.sh
|
|
parse_uri 'https://john.doe@www.example.com:123/forum/questions/?tag=networking&order=newest#top'
|
|
[ "$scheme" == 'https' ]
|
|
[ "$hostname" == 'www.example.com' ]
|
|
[ "$port" == '123' ]
|
|
[ "$path" == '/forum/questions/' ]
|
|
[ "$username" == 'john.doe' ]
|
|
[ "$password" == '' ]
|
|
[ "$query" == 'tag=networking&order=newest' ]
|
|
[ "$fragment" == 'top' ]
|
|
}
|
|
|
|
@test "ldap://[2001:db8::7]/c=GB?objectClass?one" {
|
|
. uri.sh
|
|
parse_uri 'ldap://[2001:db8::7]/c=GB?objectClass?one'
|
|
[ "$scheme" == 'ldap' ]
|
|
[ "$hostname" == '[2001:db8::7]' ]
|
|
[ "$port" == '' ]
|
|
[ "$path" == '/c=GB' ]
|
|
[ "$username" == '' ]
|
|
[ "$password" == '' ]
|
|
[ "$query" == 'objectClass?one' ]
|
|
[ "$fragment" == '' ]
|
|
}
|
|
|
|
@test "mailto:John.Doe@example.com" {
|
|
. uri.sh
|
|
parse_uri 'mailto:John.Doe@example.com'
|
|
[ "$scheme" == 'mailto' ]
|
|
[ "$hostname" == '' ]
|
|
[ "$port" == '' ]
|
|
[ "$path" == 'John.Doe@example.com' ]
|
|
[ "$username" == '' ]
|
|
[ "$password" == '' ]
|
|
[ "$query" == '' ]
|
|
[ "$fragment" == '' ]
|
|
}
|
|
|
|
@test "news:comp.infosystems.www.servers.unix" {
|
|
. uri.sh
|
|
parse_uri 'news:comp.infosystems.www.servers.unix'
|
|
[ "$scheme" == 'news' ]
|
|
[ "$hostname" == '' ]
|
|
[ "$port" == '' ]
|
|
[ "$path" == 'comp.infosystems.www.servers.unix' ]
|
|
[ "$username" == '' ]
|
|
[ "$password" == '' ]
|
|
[ "$query" == '' ]
|
|
[ "$fragment" == '' ]
|
|
}
|
|
|
|
@test "tel:+1-816-555-1212" {
|
|
. uri.sh
|
|
parse_uri 'tel:+1-816-555-1212'
|
|
[ "$scheme" == 'tel' ]
|
|
[ "$hostname" == '' ]
|
|
[ "$port" == '' ]
|
|
[ "$path" == '+1-816-555-1212' ]
|
|
[ "$username" == '' ]
|
|
[ "$password" == '' ]
|
|
[ "$query" == '' ]
|
|
[ "$fragment" == '' ]
|
|
|
|
}
|
|
|
|
@test "telnet://192.0.2.16:80/" {
|
|
. uri.sh
|
|
parse_uri 'telnet://192.0.2.16:80/'
|
|
[ "$scheme" == 'telnet' ]
|
|
[ "$hostname" == '192.0.2.16' ]
|
|
[ "$port" == '80' ]
|
|
[ "$path" == '/' ]
|
|
[ "$username" == '' ]
|
|
[ "$password" == '' ]
|
|
[ "$query" == '' ]
|
|
[ "$fragment" == '' ]
|
|
}
|
|
|
|
@test "urn:oasis:names:specification:docbook:dtd:xml:4.1.2" {
|
|
. uri.sh
|
|
parse_uri 'urn:oasis:names:specification:docbook:dtd:xml:4.1.2'
|
|
[ "$scheme" == 'urn' ]
|
|
[ "$hostname" == '' ]
|
|
[ "$port" == '' ]
|
|
[ "$path" == 'oasis:names:specification:docbook:dtd:xml:4.1.2' ]
|
|
[ "$username" == '' ]
|
|
[ "$password" == '' ]
|
|
[ "$query" == '' ]
|
|
[ "$fragment" == '' ]
|
|
}
|