Running tests with reduced privileges

Sven's Avatar


13 Nov, 2015 02:51 PM

One of my project's unittest cases depend on not being able to create file and throwing exception instead. As it runs as administrator, it always succeeds, making test fail. Is it somehow possible to launch unittest with reduced privileges?

One way is to run unittests in wrapper script with lowered 'runas /trustlevel' but runas does not return correct error code that launched application returned. It is also possible launched script to communicate back success/failure by generating result file but it feels cumbersome. Although i probably need to go this way if appveyor itself doesn't support dropping privileges somehow that i missed.

  1. Support Staff 1 Posted by Feodor Fitsner on 13 Nov, 2015 05:28 PM

    Feodor Fitsner's Avatar

    There is no built-in support for running with reduced privileges.

    I've found psexec.exe could be used for that:

    It's actually available on build workers in C:\Tools\PsTools and should be in PATH already.

  2. 2 Posted by Sven on 13 Nov, 2015 10:03 PM

    Sven's Avatar

    Thank you for answer.

    Tried psexec, it had another problem -- limited too much, now testcases that must succeed to open file, fail :)

    Anyway, managed to circumvent 'runas /trustlevel:0x20000' error level problem: google test runner generates junit XML output that can be queried for failures with powershell.

  3. 3 Posted by Ilia on 02 Aug, 2017 04:43 AM

    Ilia's Avatar

    Maybe someone else will find this useful, so I'll leave it here.
    I tried many different ways including psexec and runas, nothing worked actually.

    Finally I found quite complicated way of doing that (using openssh). But at least it works well and allows you to control the privileges like you need. Besides, it requires zero configuration from Appveyor side. The example can be found here

  4. Ilya Finkelshteyn closed this discussion on 25 Aug, 2018 02:18 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac