Windows permission during unittesting

i have a function that writes into the local app data on windows. i got the error: Os { code: 5, kind: PermissionDenied, message: "Access is denied." }. this was kind of expected, so i ran the code using the windows powershell as admin, but i got the exact same error. can anyone tell me how can i run this test without running into a permission error?

The test actually is a standalone executable located in target/debug/deps/ .
If you want give it a permission, you can run the executable directly.

You can consult this thread for details.

the project is actually in tauri, so the test actually don't work. i looked at every .exe in the deps directory, and non of them work without using npm run tauri dev. cargo test normally works without tauri, but it fails in this case. also, running every test as admin didn't solve anything.

is there really no way to request admin access in unit testing

Hi @pretro,

I am only guessing, do you know which Windows user the test is running under? Might be you have to give appropriate permissions on the target directory to that particular user?

For example, I used to work with a Delphi ISAPI. There is this specific desktop database engine, it runs under the Internet user, so we need to give write permission to the target database directory for which the ISAPI is loading look up data from.

Best regards,

...behai.

1 Like

It may be that it's part of Tauri that doesn't have access to %LOCALAPPDATA%, and which is getting the access error. Whether or not it runs as admin, parts of Tauri like the webview will be giving up most of their permissions. I don't know enough about Tauri to know if this could really be the issue.

Another option is that you actually have the access you want, but antivirus software is blocking what you're trying to do. Are you running anything more advanced than Windows Defender?

Or a third option is that your code isn't using the file path that you expect, and is trying to access something that only SYSTEM has access to. You could try adding some logging, or use Process Monitor to see what's being passed to CreateFile by your test.

3 Likes

sorry for the late answer, but i actually have no other users on my computer, it's just that for some reason, instead of asking for permission, my computer sometimes just seems to not request permission and just answer that i don't have permission. I normally use linux, and i don't have a lot of knowlage about windows, so if you have any idea why could this happen that would be very helpful

1 Like

the third one was actually the reason why. my solution was to change my user permissions from none to all, and that seems to have fixed the issue. thanks!

1 Like