Skip to content

Commit

Permalink
Prioritize Organization settings
Browse files Browse the repository at this point in the history
Now that the write permissions to the registry are irrelevant, we
need a way for the sysadmin to enforce its configuration on the machine.
To achieve this, we set the org-provided Landscape and Pro settings
as the top layer.
  • Loading branch information
EduardGomezEscandell committed Nov 14, 2023
1 parent 1b376b7 commit 8fed1e6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
16 changes: 8 additions & 8 deletions windows-agent/internal/config/config_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ type subscription struct {
}

func (s subscription) resolve() (string, Source) {
if s.Organization != "" {
return s.Organization, SourceRegistry
}

if s.Store != "" {
return s.Store, SourceMicrosoftStore
}
Expand All @@ -34,10 +38,6 @@ func (s subscription) resolve() (string, Source) {
return s.User, SourceUser
}

if s.Organization != "" {
return s.Organization, SourceRegistry
}

return "", SourceNone
}

Expand All @@ -50,13 +50,13 @@ type landscapeConf struct {
}

func (p landscapeConf) resolve() (string, Source) {
if p.UserConfig != "" {
return p.UserConfig, SourceUser
}

if p.OrgConfig != "" {
return p.OrgConfig, SourceRegistry
}

if p.UserConfig != "" {
return p.UserConfig, SourceUser
}

return "", SourceNone
}
9 changes: 5 additions & 4 deletions windows-agent/internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,10 @@ func TestSubscription(t *testing.T) {
"Success when there is a user token": {settingsState: userTokenHasValue, wantToken: "user_token", wantSource: config.SourceUser},
"Success when there is a store token": {settingsState: storeTokenHasValue, wantToken: "store_token", wantSource: config.SourceMicrosoftStore},

"Success when there are organization and user tokens": {settingsState: orgTokenHasValue | userTokenHasValue, wantToken: "user_token", wantSource: config.SourceUser},
"Success when there are organization and store tokens": {settingsState: orgTokenHasValue | storeTokenHasValue, wantToken: "store_token", wantSource: config.SourceMicrosoftStore},
"Success when there are organization and user tokens, and an empty store token": {settingsState: orgTokenHasValue | userTokenHasValue | storeTokenExists, wantToken: "user_token", wantSource: config.SourceUser},
"Success when there are organization and user tokens": {settingsState: orgTokenHasValue | userTokenHasValue, wantToken: "org_token", wantSource: config.SourceRegistry},
"Success when there are organization and store tokens": {settingsState: orgTokenHasValue | storeTokenHasValue, wantToken: "org_token", wantSource: config.SourceRegistry},
"Success when there are store and user tokens": {settingsState: userTokenHasValue | storeTokenHasValue, wantToken: "store_token", wantSource: config.SourceMicrosoftStore},
"Success when there are organization and user tokens, and an empty store token": {settingsState: orgTokenHasValue | userTokenHasValue | storeTokenExists, wantToken: "org_token", wantSource: config.SourceRegistry},

"Error when the registry key cannot be opened": {settingsState: orgTokenHasValue, mockErrors: registry.MockErrOnOpenKey, wantError: true},
"Error when the registry key cannot be read from": {settingsState: orgTokenHasValue, mockErrors: registry.MockErrReadValue, wantError: true},
Expand Down Expand Up @@ -124,7 +125,7 @@ func TestLandscapeConfig(t *testing.T) {
"Success when there is an organization conf": {settingsState: orgLandscapeConfigHasValue, wantLandscapeConfig: "[client]\nuser=BigOrg", wantSource: config.SourceRegistry},
"Success when there is a user conf": {settingsState: userLandscapeConfigHasValue, wantLandscapeConfig: "[client]\nuser=JohnDoe", wantSource: config.SourceUser},

"Success when there are organization and user confs": {settingsState: orgLandscapeConfigHasValue | userLandscapeConfigHasValue, wantLandscapeConfig: "[client]\nuser=JohnDoe", wantSource: config.SourceUser},
"Success when there are organization and user confs": {settingsState: orgLandscapeConfigHasValue | userLandscapeConfigHasValue, wantLandscapeConfig: "[client]\nuser=BigOrg", wantSource: config.SourceRegistry},

"Error when the registry key cannot be opened": {settingsState: orgTokenHasValue, mockErrors: registry.MockErrOnOpenKey, wantError: true},
"Error when the registry key cannot be read from": {settingsState: orgTokenHasValue, mockErrors: registry.MockErrReadValue, wantError: true},
Expand Down

0 comments on commit 8fed1e6

Please sign in to comment.