init
This commit is contained in:
		
							
								
								
									
										268
									
								
								tests/parse_uri.bats
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										268
									
								
								tests/parse_uri.bats
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,268 @@
 | 
			
		||||
#! /usr/bin/env bats
 | 
			
		||||
 | 
			
		||||
# lib/parse_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 "Test file:/" {
 | 
			
		||||
    . parse_uri.sh
 | 
			
		||||
    parse_uri 'file:/'
 | 
			
		||||
    [ "$scheme" == 'file' ]
 | 
			
		||||
    [ "$hostname" == '' ]
 | 
			
		||||
    [ "$port" == '' ]
 | 
			
		||||
    [ "$path" == '/' ]
 | 
			
		||||
    [ "$username" == '' ]
 | 
			
		||||
    [ "$password" == '' ]
 | 
			
		||||
    [ "$query" == '' ]
 | 
			
		||||
    [ "$fragment" == '' ]
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@test "Test file:/path" {
 | 
			
		||||
    . parse_uri.sh
 | 
			
		||||
    parse_uri 'file:/path'
 | 
			
		||||
    [ "$scheme" == 'file' ]
 | 
			
		||||
    [ "$hostname" == '' ]
 | 
			
		||||
    [ "$port" == '' ]
 | 
			
		||||
    [ "$path" == '/path' ]
 | 
			
		||||
    [ "$username" == '' ]
 | 
			
		||||
    [ "$password" == '' ]
 | 
			
		||||
    [ "$query" == '' ]
 | 
			
		||||
    [ "$fragment" == '' ]
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@test "Test file:///" {
 | 
			
		||||
    . parse_uri.sh
 | 
			
		||||
    parse_uri 'file:///'
 | 
			
		||||
    [ "$scheme" == 'file' ]
 | 
			
		||||
    [ "$hostname" == '' ]
 | 
			
		||||
    [ "$port" == '' ]
 | 
			
		||||
    [ "$path" == '/' ]
 | 
			
		||||
    [ "$username" == '' ]
 | 
			
		||||
    [ "$password" == '' ]
 | 
			
		||||
    [ "$query" == '' ]
 | 
			
		||||
    [ "$fragment" == '' ]
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@test "Test sqlite:///path" {
 | 
			
		||||
    . parse_uri.sh
 | 
			
		||||
    parse_uri 'sqlite:///path'
 | 
			
		||||
    [ "$scheme" == 'sqlite' ]
 | 
			
		||||
    [ "$hostname" == '' ]
 | 
			
		||||
    [ "$port" == '' ]
 | 
			
		||||
    [ "$path" == '/path' ]
 | 
			
		||||
    [ "$username" == '' ]
 | 
			
		||||
    [ "$password" == '' ]
 | 
			
		||||
    [ "$query" == '' ]
 | 
			
		||||
    [ "$fragment" == '' ]
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@test "Test file://host" {
 | 
			
		||||
    . parse_uri.sh
 | 
			
		||||
    parse_uri 'file://host'
 | 
			
		||||
    [ "$scheme" == 'file' ]
 | 
			
		||||
    [ "$hostname" == 'host' ]
 | 
			
		||||
    [ "$port" == '' ]
 | 
			
		||||
    [ "$path" == '' ]
 | 
			
		||||
    [ "$username" == '' ]
 | 
			
		||||
    [ "$password" == '' ]
 | 
			
		||||
    [ "$query" == '' ]
 | 
			
		||||
    [ "$fragment" == '' ]
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@test "Test s3://host/path" {
 | 
			
		||||
    . parse_uri.sh
 | 
			
		||||
    parse_uri 's3://host/path'
 | 
			
		||||
    [ "$scheme" == 's3' ]
 | 
			
		||||
    [ "$hostname" == 'host' ]
 | 
			
		||||
    [ "$port" == '' ]
 | 
			
		||||
    [ "$path" == '/path' ]
 | 
			
		||||
    [ "$username" == '' ]
 | 
			
		||||
    [ "$password" == '' ]
 | 
			
		||||
    [ "$query" == '' ]
 | 
			
		||||
    [ "$fragment" == '' ]
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@test "Test dav://user@host/" {
 | 
			
		||||
    . parse_uri.sh
 | 
			
		||||
    parse_uri 'dav://user@host/'
 | 
			
		||||
    [ "$scheme" == 'dav' ]
 | 
			
		||||
    [ "$hostname" == 'host' ]
 | 
			
		||||
    [ "$port" == '' ]
 | 
			
		||||
    [ "$path" == '/' ]
 | 
			
		||||
    [ "$username" == 'user' ]
 | 
			
		||||
    [ "$password" == '' ]
 | 
			
		||||
    [ "$query" == '' ]
 | 
			
		||||
    [ "$fragment" == '' ]
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@test "Test dav://user:p%40%24%24w0rD@host/path/" {
 | 
			
		||||
    . parse_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 "Test rsync://user:password@host:~/backups" {
 | 
			
		||||
    . parse_uri.sh
 | 
			
		||||
    parse_uri 'rsync://user:password@host:~/backups'
 | 
			
		||||
    [ "$scheme" == 'rsync' ]
 | 
			
		||||
    [ "$hostname" == 'host' ]
 | 
			
		||||
    [ "$port" == '' ]
 | 
			
		||||
    [ "$path" == '~/backups' ]
 | 
			
		||||
    [ "$username" == 'user' ]
 | 
			
		||||
    [ "$password" == 'password' ]
 | 
			
		||||
    [ "$query" == '' ]
 | 
			
		||||
    [ "$fragment" == '' ]
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@test "Test postgres://user:password@host:5432" {
 | 
			
		||||
    . parse_uri.sh
 | 
			
		||||
    parse_uri 'postgres://user:password@host:5432'
 | 
			
		||||
    [ "$scheme" == 'postgres' ]
 | 
			
		||||
    [ "$hostname" == 'host' ]
 | 
			
		||||
    [ "$port" == '5432' ]
 | 
			
		||||
    [ "$path" == '' ]
 | 
			
		||||
    [ "$username" == 'user' ]
 | 
			
		||||
    [ "$password" == 'password' ]
 | 
			
		||||
    [ "$query" == '' ]
 | 
			
		||||
    [ "$fragment" == '' ]
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@test "Test http://user:password@host:port/path?q=val" {
 | 
			
		||||
    . parse_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 "Test ftp://user:%24t%D0%AFo%7C%5C%7C6@[fe80::5054:ff:fe24:382]:2021/srv/" {
 | 
			
		||||
    . parse_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 "Test https://john.doe@www.example.com:123/forum/questions/?tag=networking&order=newest#top" {
 | 
			
		||||
    . parse_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 "Test ldap://[2001:db8::7]/c=GB?objectClass?one" {
 | 
			
		||||
    . parse_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 "Test mailto:John.Doe@example.com" {
 | 
			
		||||
    . parse_uri.sh
 | 
			
		||||
    parse_uri 'mailto:John.Doe@example.com'
 | 
			
		||||
    [ "$scheme" == 'mailto' ]
 | 
			
		||||
    [ "$hostname" == '' ]
 | 
			
		||||
    [ "$port" == '' ]
 | 
			
		||||
    [ "$path" == 'John.Doe@example.com' ]
 | 
			
		||||
    [ "$username" == '' ]
 | 
			
		||||
    [ "$password" == '' ]
 | 
			
		||||
    [ "$query" == '' ]
 | 
			
		||||
    [ "$fragment" == '' ]
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@test "Test news:comp.infosystems.www.servers.unix" {
 | 
			
		||||
    . parse_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 "Test tel:+1-816-555-1212" {
 | 
			
		||||
    . parse_uri.sh
 | 
			
		||||
    parse_uri 'tel:+1-816-555-1212'
 | 
			
		||||
    [ "$scheme" == 'tel' ]
 | 
			
		||||
    [ "$hostname" == '' ]
 | 
			
		||||
    [ "$port" == '' ]
 | 
			
		||||
    [ "$path" == '+1-816-555-1212' ]
 | 
			
		||||
    [ "$username" == '' ]
 | 
			
		||||
    [ "$password" == '' ]
 | 
			
		||||
    [ "$query" == '' ]
 | 
			
		||||
    [ "$fragment" == '' ]
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@test "Test telnet://192.0.2.16:80/" {
 | 
			
		||||
    . parse_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 "Test urn:oasis:names:specification:docbook:dtd:xml:4.1.2" {
 | 
			
		||||
    . parse_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" == '' ]
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user