github.com/vmware/govmomi@v0.43.0/govc/test/role.bats (about) 1 #!/usr/bin/env bats 2 3 load test_helper 4 5 @test "permissions" { 6 vcsim_env 7 8 perm=$(govc permissions.ls /DC0) 9 10 run govc permissions.ls -json 11 assert_success 12 13 run govc permissions.set -principal root -role Admin /DC0 14 assert_success 15 16 run govc permissions.ls /DC0 17 refute_line "$perm" 18 19 run govc permissions.remove -principal root /DC0 20 assert_success 21 22 run govc permissions.ls /DC0 23 assert_success "$perm" 24 } 25 26 @test "role.ls" { 27 vcsim_env 28 29 run govc role.ls 30 assert_success 31 32 run govc role.ls -json 33 assert_success 34 35 run govc role.ls Admin 36 assert_success 37 38 run govc role.ls -json Admin 39 assert_success 40 41 run govc role.ls enoent 42 assert_failure 43 } 44 45 @test "role.usage" { 46 vcsim_env 47 48 run govc role.usage 49 assert_success 50 51 run govc role.usage -json 52 assert_success 53 54 run govc role.usage Admin 55 assert_success 56 57 run govc role.usage -json Admin 58 assert_success 59 60 run govc role.usage enoent 61 assert_failure 62 } 63 64 @test "role.create" { 65 vcsim_env 66 67 id=$(new_id) 68 run govc role.create "$id" 69 assert_success 70 71 run govc role.ls "$id" 72 assert_success 73 74 priv=$(govc role.ls "$id" | wc -l) 75 [ "$priv" -eq 3 ] 76 77 vm_priv=($(govc role.ls Admin | grep VirtualMachine.)) 78 79 # Test set 80 run govc role.update "$id" "${vm_priv[@]}" 81 assert_success 82 83 # invalid priv id 84 run govc role.update "$id" enoent 85 assert_failure 86 87 npriv=$(govc role.ls "$id" | wc -l) 88 [ "$npriv" -gt "$priv" ] 89 priv=$npriv 90 91 op_priv=($(govc role.ls "$id" | grep VirtualMachine.GuestOperations.)) 92 # Test remove 93 run govc role.update -r "$id" "${op_priv[@]}" 94 assert_success 95 96 npriv=$(govc role.ls "$id" | wc -l) 97 [ "$npriv" -lt "$priv" ] 98 priv=$npriv 99 100 # Test add 101 run govc role.update -a "$id" "${op_priv[@]}" 102 assert_success 103 104 npriv=$(govc role.ls "$id" | wc -l) 105 [ "$npriv" -gt "$priv" ] 106 priv=$npriv 107 108 # Test rename 109 run govc role.update -name "${id}-N" "$id" 110 assert_success 111 112 id="${id}-N" 113 # Test we didn't drop any privileges during rename 114 [ "$priv" -eq "$(govc role.ls "$id" | wc -l)" ] 115 116 run govc role.remove "${id}" 117 assert_success 118 119 run govc role.ls "$id" 120 assert_failure 121 }