Skip to content
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

refactor: use CheckAuthorization instead of IsAuthorized #2319

Merged
merged 21 commits into from
Jun 20, 2024

Conversation

kingpinXD
Copy link
Contributor

@kingpinXD kingpinXD commented Jun 5, 2024

Description

This pr refactors the codebase to use the CheckAuthorization function instead of the the older IsAuthorized

Closes: #2153
#2247

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Include instructions and any relevant details so others can reproduce.

  • Tested CCTX in localnet
  • Tested in development environment
  • Go unit tests
  • Go integration tests
  • Tested via GitHub Actions

Checklist:

  • I have added unit tests that prove my fix feature works

@kingpinXD kingpinXD changed the title refactor: use CheckAuthorization istead of IsAuthorized refactor: use CheckAuthorization instead of IsAuthorized Jun 5, 2024
@kingpinXD kingpinXD changed the base branch from develop to authorization-list-check-messages June 5, 2024 00:26
Copy link
Contributor

@skosito skosito left a comment

Choose a reason for hiding this comment

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

lgtm from draft perspective, it seems all calls are equivalent, it is just on api level?

x/crosschain/types/expected_keepers.go Outdated Show resolved Hide resolved
@kingpinXD
Copy link
Contributor Author

lgtm from draft perspective, it seems all calls are equivalent, it is just on api level?

Yes , the new function returns an error instead of bool , and accepts different params

Base automatically changed from authorization-list-check-messages to develop June 6, 2024 14:28
Copy link

github-actions bot commented Jun 6, 2024

!!!WARNING!!!
nosec detected in the following files: x/observer/keeper/msg_server_update_observer_test.go

Be very careful about using #nosec in code. It can be a quick way to suppress security warnings and move forward with development, it should be employed with caution. Suppressing warnings with #nosec can hide potentially serious vulnerabilities. Only use #nosec when you're absolutely certain that the security issue is either a false positive or has been mitigated in another way.

Only suppress a single rule (or a specific set of rules) within a section of code, while continuing to scan for other problems. To do this, you can list the rule(s) to be suppressed within the #nosec annotation, e.g: /* #nosec G401 */ or //#nosec G201 G202 G203
Broad #nosec annotations should be avoided, as they can hide other vulnerabilities. The CI will block you from merging this PR until you remove #nosec annotations that do not target specific rules.

Pay extra attention to the way #nosec is being used in the files listed above.

@github-actions github-actions bot added the nosec label Jun 6, 2024
Copy link

codecov bot commented Jun 6, 2024

Codecov Report

Attention: Patch coverage is 98.41270% with 2 lines in your changes missing coverage. Please review.

Project coverage is 68.66%. Comparing base (2bb6f7b) to head (e83e188).

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #2319      +/-   ##
===========================================
- Coverage    68.72%   68.66%   -0.06%     
===========================================
  Files          302      302              
  Lines        19169    19153      -16     
===========================================
- Hits         13174    13152      -22     
- Misses        5348     5351       +3     
- Partials       647      650       +3     
Files Coverage Δ
x/authority/keeper/authorization_list.go 100.00% <ø> (ø)
x/authority/keeper/msg_server_add_authorization.go 85.71% <100.00%> (-14.29%) ⬇️
...uthority/keeper/msg_server_remove_authorization.go 76.47% <100.00%> (-23.53%) ⬇️
x/authority/keeper/msg_server_update_chain_info.go 100.00% <100.00%> (ø)
x/authority/types/authorization_list.go 100.00% <ø> (ø)
x/authority/types/genesis.go 100.00% <100.00%> (ø)
x/crosschain/keeper/msg_server_abort_stuck_cctx.go 100.00% <100.00%> (ø)
...rosschain/keeper/msg_server_add_inbound_tracker.go 94.73% <100.00%> (+0.45%) ⬆️
...osschain/keeper/msg_server_add_outbound_tracker.go 83.54% <100.00%> (+0.42%) ⬆️
.../crosschain/keeper/msg_server_migrate_tss_funds.go 83.22% <100.00%> (-0.23%) ⬇️
... and 25 more

@kingpinXD kingpinXD marked this pull request as ready for review June 6, 2024 18:53
@kingpinXD kingpinXD requested a review from skosito June 6, 2024 19:13
@kingpinXD
Copy link
Contributor Author

Restructuting the tests so that for every message the lines of code look like

msg := ...
MockCheckAuthorization
msgServer.XXX 

This would improve readability as the message would be declared right before its used. The change is only cosmetic however and the pr review can be started before I push those changes in

Copy link
Member

@lumtis lumtis left a comment

Choose a reason for hiding this comment

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

In general throughout the code, I think it would be cleaner to use one-liner for if checks:

err := k.GetAuthorityKeeper().CheckAuthorization(ctx, msg)
if err != nil {
	return false, errorsmod.Wrap(authoritytypes.ErrUnauthorized, err.Error())
}

to

if err := k.GetAuthorityKeeper().CheckAuthorization(ctx, msg); err != nil {
	return false, errorsmod.Wrap(authoritytypes.ErrUnauthorized, err.Error())
}

changelog.md Outdated Show resolved Hide resolved
x/authority/keeper/msg_server_remove_authorization_test.go Outdated Show resolved Hide resolved
x/authority/keeper/msg_server_update_chain_info_test.go Outdated Show resolved Hide resolved
x/crosschain/keeper/msg_server_add_inbound_tracker.go Outdated Show resolved Hide resolved
x/observer/keeper/msg_server_remove_chain_params_test.go Outdated Show resolved Hide resolved
x/observer/keeper/msg_server_remove_chain_params_test.go Outdated Show resolved Hide resolved
x/observer/keeper/msg_server_remove_chain_params_test.go Outdated Show resolved Hide resolved
x/observer/keeper/msg_server_reset_chain_nonces_test.go Outdated Show resolved Hide resolved
x/observer/keeper/msg_server_update_chain_params_test.go Outdated Show resolved Hide resolved
@kingpinXD kingpinXD requested a review from swift1337 as a code owner June 19, 2024 15:28
Copy link
Member

@lumtis lumtis left a comment

Choose a reason for hiding this comment

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

LGTM

@lumtis
Copy link
Member

lumtis commented Jun 20, 2024

@kingpinXD please check related issues are attached when opening the PR

Copy link

gitguardian bot commented Jun 20, 2024

⚠️ GitGuardian has uncovered 1 secret following the scan of your pull request.

Please consider investigating the findings and remediating the incidents. Failure to do so may lead to compromising the associated services or software components.

🔎 Detected hardcoded secret in your pull request
GitGuardian id GitGuardian status Secret Commit Filename
11759679 Triggered Generic High Entropy Secret e53c8c3 cmd/zetae2e/local/accounts.go View secret
🛠 Guidelines to remediate hardcoded secrets
  1. Understand the implications of revoking this secret by investigating where it is used in your code.
  2. Replace and store your secret safely. Learn here the best practices.
  3. Revoke and rotate this secret.
  4. If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.

To avoid such incidents in the future consider


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

@kingpinXD kingpinXD merged commit ca9b90f into develop Jun 20, 2024
19 checks passed
@kingpinXD kingpinXD deleted the authorization-list-tests branch June 20, 2024 21:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use PolicyTable for authorization zetacore : Refactor MockIsAuthorized function
3 participants