|
7 | 7 | let (:system_bytes) { [1, 1, 0, 0, 0, 0, 0, 5, 18, 0, 0, 0] }
|
8 | 8 | let (:null_sid_bytes) { [1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] }
|
9 | 9 | let (:administrator_bytes) { [1, 2, 0, 0, 0, 0, 0, 5, 32, 0, 0, 0, 32, 2, 0, 0] }
|
| 10 | + let (:all_application_packages_bytes) { [1, 2, 0, 0, 0, 0, 0, 15, 2, 0, 0, 0, 1, 0, 0, 0] } |
10 | 11 | let (:computer_sid) { Puppet::Util::Windows::SID.name_to_principal(Puppet::Util::Windows::ADSI.computer_name) }
|
11 | 12 | # BUILTIN is localized on German Windows, but not French
|
12 | 13 | # looking this up like this dilutes the values of the tests as we're comparing two mechanisms
|
|
121 | 122 | expect(principal.to_s).to eq(builtin_localized)
|
122 | 123 | end
|
123 | 124 |
|
| 125 | + it "should always sanitize the account name first" do |
| 126 | + expect(Puppet::Util::Windows::SID::Principal).to receive(:sanitize_account_name).with('NT AUTHORITY\\SYSTEM').and_call_original |
| 127 | + Puppet::Util::Windows::SID::Principal.lookup_account_name('NT AUTHORITY\\SYSTEM') |
| 128 | + end |
| 129 | + |
| 130 | + it "should be able to create an instance from an account name prefixed by APPLICATION PACKAGE AUTHORITY" do |
| 131 | + principal = Puppet::Util::Windows::SID::Principal.lookup_account_name('APPLICATION PACKAGE AUTHORITY\\ALL APPLICATION PACKAGES') |
| 132 | + expect(principal.account).to eq('ALL APPLICATION PACKAGES') |
| 133 | + expect(principal.sid_bytes).to eq(all_application_packages_bytes) |
| 134 | + expect(principal.sid).to eq('S-1-15-2-1') |
| 135 | + expect(principal.domain).to eq('APPLICATION PACKAGE AUTHORITY') |
| 136 | + expect(principal.domain_account).to eq('APPLICATION PACKAGE AUTHORITY\\ALL APPLICATION PACKAGES') |
| 137 | + expect(principal.account_type).to eq(:SidTypeWellKnownGroup) |
| 138 | + expect(principal.to_s).to eq('APPLICATION PACKAGE AUTHORITY\\ALL APPLICATION PACKAGES') |
| 139 | + end |
| 140 | + |
| 141 | + it "should fail without proper account name sanitization when it is prefixed by APPLICATION PACKAGE AUTHORITY" do |
| 142 | + given_account_name = 'APPLICATION PACKAGE AUTHORITY\\ALL APPLICATION PACKAGES' |
| 143 | + expect { Puppet::Util::Windows::SID::Principal.lookup_account_name(nil, false, given_account_name) }.to raise_error(Puppet::Util::Windows::Error, /No mapping between account names and security IDs was done./) |
| 144 | + end |
124 | 145 | end
|
125 | 146 |
|
126 | 147 | describe ".lookup_account_sid" do
|
|
0 commit comments