178 lines
4.3 KiB
Plaintext
178 lines
4.3 KiB
Plaintext
# Get a Mullvad api access token from an account number
|
|
def "m token" [
|
|
account: string # Mullvad account number
|
|
] {
|
|
(http post https://api.mullvad.net/auth/v1/token
|
|
-t application/json {account_number: $account}
|
|
).access_token
|
|
}
|
|
|
|
# Add a device to a mullvad account
|
|
def "m add device" [
|
|
account: string # Mullvad account number
|
|
] {
|
|
let token = (m-token $account)
|
|
let bearer = ("Bearer " + $token)
|
|
|
|
(http post https://api.mullvad.net/accounts/v1/devices
|
|
-t application/json
|
|
-H [Authorization $bearer]
|
|
{
|
|
pubkey: (wg genkey | wg pubkey),
|
|
hijack_dns: false,
|
|
kind: "App",
|
|
})
|
|
}
|
|
|
|
# Get mullvad-daemon system path
|
|
def "m daemon path" []: nothing -> string {
|
|
match (uname).kernel-name {
|
|
Linux => "/usr/bin/mullvad-daemon",
|
|
Darwin => "/Applications/Mullvad VPN.app/Contents/Resources/mullvad-daemon",
|
|
_ => (panic "Unknown Kernel"),
|
|
}
|
|
}
|
|
|
|
# Return true if mullvad-daemon is running
|
|
def "m daemon is-running" [
|
|
# Only return true if mullvad-daemon is running as a launch daemon
|
|
--system (-s),
|
|
] {
|
|
let procs = (^ps aux | lines)
|
|
if $system {
|
|
$procs | any { |line| $line =~ (m daemon path) }
|
|
} else {
|
|
$procs | any { |line| $line =~ "mullvad-daemon" }
|
|
}
|
|
}
|
|
|
|
def dns [
|
|
name: string,
|
|
] {
|
|
nslookup $name |
|
|
parse -r "Address:\\s(?<ipv4>\\d+\\.\\d+\\.\\d+\\.\\d+)|Address:\\s(?<ipv6>[\\d:a-z]+)" |
|
|
each { |row|
|
|
if $row.ipv4 != "" {
|
|
{ kind: ipv4, addr: $row.ipv4 }
|
|
} else {
|
|
{ kind: ipv6, addr: $row.ipv6 }
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
# Build and run mullvad-daemon
|
|
def "m daemon" [
|
|
--release (-r)
|
|
--boringtun
|
|
--stagemole
|
|
] {
|
|
mut cargo_flags = []
|
|
mut envs = [
|
|
MULLVAD_RESOURCE_DIR=./dist-assets/
|
|
]
|
|
|
|
if $release {
|
|
$cargo_flags ++= [--release]
|
|
}
|
|
|
|
if $stagemole {
|
|
$cargo_flags ++= [--features api-override]
|
|
$envs ++= [
|
|
MULLVAD_API_HOST=api.stagemole.eu
|
|
MULLVAD_API_ADDR=(dns api.stagemole.eu | where kind == ipv4 | get 0.addr):443
|
|
]
|
|
}
|
|
|
|
if (m daemon is-running --system) {
|
|
print "daemon is loaded, stopping..."
|
|
|
|
match (uname).kernel-name {
|
|
Linux => {
|
|
sudo systemctl stop mullvad-daemon
|
|
},
|
|
Darwin => {
|
|
sudo launchctl unload -w /Library/LaunchDaemons/net.mullvad.daemon.plist
|
|
},
|
|
_ => (panic "Unknown Kernel"),
|
|
}
|
|
} else if (m daemon is-running) {
|
|
print "mulvad-daemon is running in another terminal"
|
|
return
|
|
}
|
|
|
|
|
|
let daemon_path = if $release {
|
|
$"($env.CARGO_TARGET_DIR)/release/mullvad-daemon"
|
|
} else {
|
|
$"($env.CARGO_TARGET_DIR)/debug/mullvad-daemon"
|
|
}
|
|
|
|
cargo b ...$cargo_flags
|
|
sudo ...$envs $daemon_path -vv
|
|
}
|
|
|
|
def "m e2e list" [
|
|
...args
|
|
] {
|
|
print "Building test utils"
|
|
cargo b --target aarch64-apple-darwin
|
|
|
|
let test_manager = $"($env.CARGO_TARGET_DIR)/aarch64-apple-darwin/debug/test-manager"
|
|
|
|
print "Listing tests"
|
|
^$test_manager list-tests ...$args | from tsv | into int priority | sort-by priority name
|
|
}
|
|
|
|
def "m e2e run" [
|
|
account: string
|
|
--skip: list<string>
|
|
...tests
|
|
] {
|
|
let commit = (git rev-parse HEAD | take 6 | decode)
|
|
print $"Current commit: ($commit)"
|
|
|
|
let dist = "../dist"
|
|
print $"Looking in ($dist)"
|
|
|
|
let pkgs = (ls $dist | where name =~ ".*\\.pkg")
|
|
let pkgs = ($pkgs | where name =~ $commit)
|
|
|
|
if ($pkgs | is-empty) {
|
|
print "No .pkg for current commit found."
|
|
print "Run ./build.sh"
|
|
return
|
|
}
|
|
|
|
if ($pkgs | length) > 1 {
|
|
print "Multiple .pkg:s for current commit found."
|
|
print "Make sure there's only one"
|
|
print ...$pkgs
|
|
return
|
|
}
|
|
|
|
let pkg = ($pkgs | get 0.name)
|
|
|
|
print $"Using ($pkg)"
|
|
|
|
print "Building test utils"
|
|
cargo b --target aarch64-apple-darwin
|
|
|
|
let test_manager = $"($env.CARGO_TARGET_DIR)/aarch64-apple-darwin/debug/test-manager"
|
|
|
|
mut args = [
|
|
--vm macos15
|
|
--account $account
|
|
--app-package $pkg
|
|
]
|
|
|
|
for s in $skip {
|
|
$args ++= ["--skip" $s]
|
|
}
|
|
let args = $args
|
|
|
|
print "Running tests"
|
|
RUST_LOG=debug ^$test_manager run-tests -v ...$args ...$tests
|
|
}
|
|
|