repositories

NixDaemon

NixOS pentest workstation as one flake — IceBreaker's successor

clonegit clone https://git.daemon-sec.xyz/NixDaemon.git
test_global_aliases.zunit55 lines1.5 KiBraw download
#!/usr/bin/env zunit

@test 'global aliases no match' {
    alias -g hw="Hello World!"
    run _check_global_aliases "echo 'hello'"

    assert "$output" is_empty
    assert $state equals 0
}

@test 'global aliases match' {
    alias -g NE="2>/dev/null"
    run _check_global_aliases "echo 'hello' 2>/dev/null"

    assert "$output" contains 'Found existing global alias for "2>/dev/null". You should use: "NE"'
    # hardcore mode is not enabled and should not show up
    assert "$output" does_not_contain 'hardcore mode enabled'
    assert $state equals 0
}

@test 'global aliases match - with hardcore mode enabled' {
    alias -g NE="2>/dev/null"
    export YSU_HARDCORE=1
    run _check_global_aliases "echo 'hello' 2>/dev/null"

    assert "$output" contains 'Found existing global alias for "2>/dev/null". You should use: "NE"'
    assert "$output" contains 'hardcore mode enabled'
    assert $state equals $HARDCORE_EXIT_CODE
}

@test 'test doesnt match substrings' {
    alias -g n="nvim"
    run _check_global_aliases "nvimkaowjqwe"

    assert "$output" is_empty
    assert $state equals 0
}

@test 'global aliases ignore on sudo' {
    alias -g NE="2>/dev/null"
    run _check_global_aliases "sudo echo 'hello' 2>/dev/null"

    assert "$output" is_empty
    assert $state equals 0
}

@test 'global aliases - does not report an ignored alias' {
    export YSU_MODE="ALL"
    export YSU_IGNORED_GLOBAL_ALIASES=("..." "NE")
    alias -g ...="../.."
    run _check_global_aliases "cd ../.."

    assert $output is_empty
    assert $state equals 0
}