Skip to content

chore: add dbauthz to unhanger tests #14394

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 22, 2024

Conversation

spikecurtis
Copy link
Contributor

@spikecurtis spikecurtis commented Aug 22, 2024

relates to #14393

customer is having issues with the unhanger failing to kill a hung build. I noticed that our unhanger unit tests don't actually use the dbauthz. This PR adds authz to the unhanger tests.

Many tests failed on template import and template dry-run jobs, because the test code inserts build jobs without a corresponding template version, and our authz layer uses permission on the template version as a proxy for permission on the job.

I'm pretty sure that our actual API calls ensure that there is always a template version for the the job, but for some future work, it would be nice to have the database enforce this.

Copy link
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @spikecurtis and the rest of your teammates on Graphite Graphite

@spikecurtis spikecurtis requested a review from Emyrk August 22, 2024 10:41
@spikecurtis spikecurtis marked this pull request as ready for review August 22, 2024 10:41
@spikecurtis spikecurtis force-pushed the spike/14393-unhanger-dbauthz-tests branch from 196399c to 3a2c955 Compare August 22, 2024 11:09
Copy link
Member

@Emyrk Emyrk left a comment

Choose a reason for hiding this comment

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

Minor nits, not blocking

@@ -37,7 +43,7 @@ func TestDetectorNoJobs(t *testing.T) {
statsCh = make(chan unhanger.Stats)
)

detector := unhanger.New(ctx, db, pubsub, log, tickCh).WithStatsChannel(statsCh)
detector := unhanger.New(ctx, wrapDBAuthz(db, log), pubsub, log, tickCh).WithStatsChannel(statsCh)
Copy link
Member

Choose a reason for hiding this comment

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

Feels odd to have a raw db laying around outside this function call scope. I'd probably do this to not have a db laying around. Up to you 🤷‍♂️

	var (
		ctx         = testutil.Context(t, testutil.WaitLong)
		rdb, pubsub = dbtestutil.NewDB(t)
		db          = wrapDBAuthz(rdb, slogtest.Make(t, nil))
		log         = slogtest.Make(t, nil)
		tickCh      = make(chan time.Time)
		statsCh     = make(chan unhanger.Stats)
	)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The annoying thing about that is that I'd have to set up a dbauthz principal for the calls that write the job, user, template, etc. Authz for those operations is irrelevant to this test.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, yea it is annoying. dbgen gets around that with a genCtx:

var genCtx = dbauthz.As(context.Background(), rbac.Subject{

If you use dbgen to handle all the initial state, you can ignore that requirement.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Almost, but not quite all state is dbgen. It make sense to me to keep this way, since it really is just the unhanger under test here, so only it need the dbauthz.

@spikecurtis spikecurtis force-pushed the spike/14393-unhanger-dbauthz-tests branch from 3a2c955 to b4ba388 Compare August 22, 2024 18:02
@spikecurtis spikecurtis force-pushed the spike/14393-unhanger-dbauthz-tests branch from b4ba388 to 4ce4ada Compare August 22, 2024 18:12
@spikecurtis spikecurtis merged commit d52bc91 into main Aug 22, 2024
28 checks passed
Copy link
Contributor Author

Merge activity

@spikecurtis spikecurtis deleted the spike/14393-unhanger-dbauthz-tests branch August 22, 2024 18:23
@github-actions github-actions bot locked and limited conversation to collaborators Aug 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants