chocolatey / chocolatey-licensed-issues

Issues for Licensed Editions of Chocolatey
19 stars 13 forks source link

Filtering of sources doesn't return correct list when `useBackgroundServiceWithSelfServiceSourcesOnly` is disabled #263

Closed sync-by-unito[bot] closed 2 years ago

sync-by-unito[bot] commented 2 years ago

Description

Within v2.2.0 of Chocolatey Licensed, we released a feature which filters source (what is output when running choco source list or when installing software) to show only the sources that can be used by the current user, based on the configuration that is in place.

For example, if you are logged in as a non-administator user, and a source is marked as admin only, this source will not be returned, since the currently logged in user cannot use that source.

In addition, based on whether or not background service is enabled, again the list of sources will be filtered to show only the sources that can be used.

This feature was added since there were times when there was confusion about not being able to install a package from a source since the source would show as being available, but then the package wouldn't be installed, since at the time of execution, the source wasn't being used. Showing only the sources that can be used means that there is less confusion overall about the current situation.

Having said that, the logic that was put in place doesn't take in account the useBackgroundServiceWithSelfServiceSourcesOnly feature. When this is enabled, which is the default, and running with Background Service enabled, it will force the usage of source that are explicitly marked as being for self service, no other sources will be returned. However, when this feature is disabled, the source filtering should return other sources that are not marked as self service, when running in self service mode.

This issue could result in 0 sources being returned, when prior to v2.2.0 sources were returned.

Steps To Reproduce

mkdir c:/testSource-NothingSet
mkdir c:/testSource-AdminOnly
mkdir c:/testSource-SelfSevice
mkdir c:/testSource-SelfSeviceAdminOnly
mkdir c:/testSource-Disabled
mkdir c:/testSource-DisabledAdminOnly
mkdir c:/testSource-DisabledSelfService
mkdir c:/testSource-DisabledSelfServiceAdminOnly

choco source add -n testSource-NothingSet -s C:\testSource-NothingSet\ choco source add -n testSource-AdminOnly -s C:\testSource-AdminOnly\ --adminOnly choco source add -n testSource-SelfService -s C:\testSource-SelfService\ --allowSelfService choco source add -n testSource-SelfServiceAdminOnly -s C:\testSource-SelfServiceAdminOnly\ --allowSelfService --adminOnly choco source add -n testSource-Disabled -s C:\testSource-Disabled\ choco source add -n testSource-DisabledAdminOnly -s C:\testSource-DisabledAdminOnly\ --adminOnly choco source add -n testSource-DisabledSelfService -s C:\testSource-DisabledSelfService\ --allowSelfService choco source add -n testSource-DisabledSelfServiceAdminOnly -s C:\testSource-DisabledSelfServiceAdminOnly\ --allowSelfService --adminOnly

choco source disable -n testSource-Disabled choco source disable -n testSource-DisabledAdminOnly choco source disable -n testSource-DisabledSelfService choco source disable -n testSource-DisabledSelfServiceAdminOnly
choco feature enable --name="useBackgroundService"
choco feature disable --name="useBackgroundServiceWithSelfServiceSourcesOnly"
choco feature disable --name="useBackgroundServiceWithNonAdministratorsOnly"
choco source list
choco source list 

Output Log

N/A

Workarounds

In the interim, marking a source as explicitly being for Self Service should result in it correctly being returned.

Proposed Solution

The filtering of the sources needs to be updated to account for for the UseBackgroundServiceWithSelfServiceSourcesOnly flag. Currently this is being ignored. As a result, when Self Service is enabled, only sources marked explicitly as being enabled for self service are being returned.

Related Issues and Tickets

Done Checklist

┆Issue is synchronized with this Gitlab issue by Unito ┆Milestone: 2.2.1