Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

authz/azuredevops: Check enforcePermissions in NewAuthzProviders#48549

Merged
indradhanush merged 6 commits into
mainfrom
ig/ado-user-perms-improvement
Mar 2, 2023
Merged

authz/azuredevops: Check enforcePermissions in NewAuthzProviders#48549
indradhanush merged 6 commits into
mainfrom
ig/ado-user-perms-improvement

Conversation

@indradhanush

@indradhanush indradhanush commented Mar 2, 2023

Copy link
Copy Markdown
Contributor

We do not want to run permission sync for orgs and projects that are declared in code host connections without an explicit enforcePermissions: true. Skip them instead.

Follow up to https://github.com/sourcegraph/sourcegraph/pull/48209#discussion_r1122990998.

Fixes #47165.

Note to reviewers

The code change itself is small but important. Most of the added and removed lines is new tests and some refactoring of the tests.

I've added inline comments to explain the changes which should make it reviewing this more approachable.

Test plan

  • Added tests
  • Build should pass

Comment on lines -80 to -82
invalidConnections []string
problems []string
warnings []string

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now we test for these in the newly added top level test TestProvider_NewAuthzProviders. Previously we were testing implicitly for NewAuthzProviders in this test itself, but it's better to have a separate test.

Comment on lines -94 to -106
{
name: "licensing feature disabled",
input: input{
mockCheckFeature: func(_ licensing.Feature) error {
return errors.New("not allowed")
},
connection: &schema.AzureDevOpsConnection{},
},
output: output{
invalidConnections: []string{"azuredevops"},
problems: []string{"not allowed"},
},
},

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved up to the new test.

}

type input struct {
mockCheckFeature func(licensing.Feature) error

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the unit tests in this want the licensing check to pass. Removed it as an input and explicitly setting it below at the start of testing.

invalidConnections []string
problems []string
warnings []string
providers []authz.Provider

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the same for all the tests - expectedProvidrers. Stopped passing it as an arg and instead using expectedProviders directly.

connection: &schema.AzureDevOpsConnection{
Orgs: []string{"solarsystem"},
Projects: []string{"solar/system"},
EnforcePermissions: true,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needed to start setting this for the tests to pass as a result of the new change in this PR.

conf.Mock(nil)
})

licensing.MockCheckFeature = tc.mockCheckFeature

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Set this once for all the unit tests here.

@sourcegraph-bot

sourcegraph-bot commented Mar 2, 2023

Copy link
Copy Markdown
Contributor

Codenotify: Notifying subscribers in CODENOTIFY files for diff 80a3b67...65846fe.

Notify File(s)
@unknwon enterprise/internal/authz/azuredevops/provider.go
enterprise/internal/authz/azuredevops/provider_test.go

@indradhanush indradhanush requested review from a team March 2, 2023 14:47
@indradhanush indradhanush self-assigned this Mar 2, 2023
@indradhanush indradhanush added the ADO Tier 1 support for Azure DevOps label Mar 2, 2023

@kopancek kopancek left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me

if len(conns) == 0 {
return initResults
}
validAzureDevOpsConnections := []*types.AzureDevOpsConnection{}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naming is hard, maybe call this authorizedConnections instead? Or connectionsWithPermissions. Valid evokes in me as if some other config was invalid :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that name. Going ahead with authorizedConnections. 👍

@indradhanush indradhanush enabled auto-merge (squash) March 2, 2023 15:06
@indradhanush indradhanush merged commit 956596d into main Mar 2, 2023
@indradhanush indradhanush deleted the ig/ado-user-perms-improvement branch March 2, 2023 15:23
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

ADO Tier 1 support for Azure DevOps cla-signed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement user permissions sync for Azure code host

3 participants