Skip to content

Lg 14425 pii column tag#11316

Merged
MrNagoo merged 11 commits intomainfrom
lg-14425-pii-column-tag
Oct 8, 2024
Merged

Lg 14425 pii column tag#11316
MrNagoo merged 11 commits intomainfrom
lg-14425-pii-column-tag

Conversation

@samathad2023
Copy link
Contributor

@samathad2023 samathad2023 commented Oct 4, 2024

🎫 Ticket

Link to the relevant ticket:
LG-14425

🛠 Summary of changes

Migrations to add sensitive tag to all columns and failure on CI on none sensitive tag detention

📜 Testing Plan

Provide a checklist of steps to confirm the changes.

  • Run the migrations
  • Verify Specs pass
  • rake task to validate the column tag
  • create local migration and see test failures

👀 Screenshots

Helpful test error. image

@samathad2023 samathad2023 force-pushed the lg-14425-pii-column-tag branch from e51a701 to f680c75 Compare October 4, 2024 18:54
.gitlab-ci.yml Outdated
script:
- *bundle_install
- bundle exec rake db:create db:migrate --trace
- bundle exec rake db:check_for_sensitive_columns
Copy link
Contributor

Choose a reason for hiding this comment

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

what if we added this code as a spec instead? spec/db/schema_spec.rb and had it do the same check? easier to see output in tests or re-run

Comment on lines +4 to +7
around do |ex|
ex.run
rescue SystemExit
end
Copy link
Contributor

Choose a reason for hiding this comment

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

I was missing this piece to actually swallow the systemExit.

if missing_columns.any?
puts 'Columns with sensitivity comments found:'
missing_columns.each { |column| puts column }
exit(-1)
Copy link
Contributor

Choose a reason for hiding this comment

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

swapped to exit instead of abort w/message because I'd have to spy the Kernal to avoid sysout

@MrNagoo MrNagoo marked this pull request as ready for review October 7, 2024 19:06
Comment on lines +16 to +18
it 'checks for columns with sensitivity comments' do
expect { task.execute }.to output(/All columns have sensitivity comments./).to_stdout
end
Copy link
Contributor

Choose a reason for hiding this comment

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

should we update the description or failure message to have example so that when this fails, people have clear instructions to follow to add comments in their migrations and fix the errors?

something like

in your migration file, add `comment: "sensitive=false"` to all columns added

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, I suppose I either shouldn't suppress puts or leave a comment in the tests to run the task locally.

Copy link
Contributor

@zachmargolis zachmargolis Oct 7, 2024

Choose a reason for hiding this comment

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

maybe there's a way to capture the STDOUT and then put that as the test expectation? This would just print the string it got instead

Suggested change
it 'checks for columns with sensitivity comments' do
expect { task.execute }.to output(/All columns have sensitivity comments./).to_stdout
end
it 'checks for columns with sensitivity comments' do
stdout = StringIO.new('')
stub_const(STDOUT, stdout)
task.execute
expect(stdout.string).to match(/All columns have sensitivity comments./)
end

Copy link
Contributor

Choose a reason for hiding this comment

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

TIL if you expect output after a rake task executes with an exit(1)... it will always pass.

Copy link
Contributor

Choose a reason for hiding this comment

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

TBH I'm not 100% sure that a rake task is the best approach for this, especially if we want to test exit codes and things, that gets very challenging. Just a spec that checks the columsn would be fine

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I don't think we want to test the exit codes. The rake task is nice to run as a one-off. I think it's in a good spot now.


it 'displays the missing column directions' do
expect { task.execute }.to output(
/In your migration, add 'comment: sensitive=false'\(or true for sensitive data\)/,
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm ensuring a test would fail with the correct output statement.

@MrNagoo MrNagoo merged commit bfb9174 into main Oct 8, 2024
@MrNagoo MrNagoo deleted the lg-14425-pii-column-tag branch October 8, 2024 12:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants