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

[PM-11764] Implement account switching and sdk initialization #1116

Merged

Conversation

coroiu
Copy link
Contributor

@coroiu coroiu commented Oct 7, 2024

🎟️ Tracking

📔 Objective

  • Expose crypto client
  • Add error handling

⏰ Reminders before review

  • Contributor guidelines followed
  • All formatters and local linters executed and passed
  • Written new unit and / or integration tests where applicable
  • Protected functional changes with optionality (feature flags)
  • Used internationalization (i18n) for all UI strings
  • CI builds passed
  • Communicated to DevOps any deployment requirements
  • Updated any necessary documentation (Confluence, contributing docs) or informed the documentation
    team

🦮 Reviewer guidelines

  • 👍 (:+1:) or similar for great changes
  • 📝 (:memo:) or ℹ️ (:information_source:) for notes or general info
  • ❓ (:question:) for questions
  • 🤔 (:thinking:) or 💭 (:thought_balloon:) for more open inquiry that's not quite a confirmed
    issue and could potentially benefit from discussion
  • 🎨 (:art:) for suggestions / improvements
  • ❌ (:x:) or ⚠️ (:warning:) for more significant problems or concerns needing attention
  • 🌱 (:seedling:) or ♻️ (:recycle:) for future improvements or indications of technical debt
  • ⛏ (:pick:) for minor or nitpick changes

Copy link
Contributor

github-actions bot commented Oct 7, 2024

Logo
Checkmarx One – Scan Summary & Details5afd425f-b205-452e-9518-cd86a90dbd44

New Issues

Severity Issue Source File / Package Checkmarx Insight
MEDIUM Privacy_Violation /languages/go/example/example.go: 103 Attack Vector
MEDIUM Unpinned Actions Full Length Commit SHA /publish-php.yml: 177 Pinning an action to a full length commit SHA is currently the only way to use an action as an immutable release. Pinning to a particular SHA helps...
MEDIUM Unpinned Actions Full Length Commit SHA /build-cli.yml: 338 Pinning an action to a full length commit SHA is currently the only way to use an action as an immutable release. Pinning to a particular SHA helps...
MEDIUM Unpinned Actions Full Length Commit SHA /publish-ruby.yml: 92 Pinning an action to a full length commit SHA is currently the only way to use an action as an immutable release. Pinning to a particular SHA helps...
MEDIUM Unpinned Actions Full Length Commit SHA /publish-rust-crates.yml: 77 Pinning an action to a full length commit SHA is currently the only way to use an action as an immutable release. Pinning to a particular SHA helps...
MEDIUM Unpinned Actions Full Length Commit SHA /publish-internal.yml: 68 Pinning an action to a full length commit SHA is currently the only way to use an action as an immutable release. Pinning to a particular SHA helps...
MEDIUM Unpinned Actions Full Length Commit SHA /publish-php.yml: 90 Pinning an action to a full length commit SHA is currently the only way to use an action as an immutable release. Pinning to a particular SHA helps...
MEDIUM Unpinned Actions Full Length Commit SHA /publish-internal.yml: 62 Pinning an action to a full length commit SHA is currently the only way to use an action as an immutable release. Pinning to a particular SHA helps...
MEDIUM Unpinned Actions Full Length Commit SHA /publish-python.yml: 108 Pinning an action to a full length commit SHA is currently the only way to use an action as an immutable release. Pinning to a particular SHA helps...
MEDIUM Unpinned Actions Full Length Commit SHA /publish-bws.yml: 93 Pinning an action to a full length commit SHA is currently the only way to use an action as an immutable release. Pinning to a particular SHA helps...
MEDIUM Unpinned Actions Full Length Commit SHA /release-ruby.yml: 51 Pinning an action to a full length commit SHA is currently the only way to use an action as an immutable release. Pinning to a particular SHA helps...
MEDIUM Unpinned Actions Full Length Commit SHA /build-cli-docker.yml: 131 Pinning an action to a full length commit SHA is currently the only way to use an action as an immutable release. Pinning to a particular SHA helps...
MEDIUM Unpinned Actions Full Length Commit SHA /publish-wasm.yml: 87 Pinning an action to a full length commit SHA is currently the only way to use an action as an immutable release. Pinning to a particular SHA helps...
MEDIUM Unpinned Actions Full Length Commit SHA /release-swift.yml: 74 Pinning an action to a full length commit SHA is currently the only way to use an action as an immutable release. Pinning to a particular SHA helps...
MEDIUM Unpinned Actions Full Length Commit SHA /build-cli-docker.yml: 54 Pinning an action to a full length commit SHA is currently the only way to use an action as an immutable release. Pinning to a particular SHA helps...
MEDIUM Unpinned Actions Full Length Commit SHA /build-cli-docker.yml: 61 Pinning an action to a full length commit SHA is currently the only way to use an action as an immutable release. Pinning to a particular SHA helps...
MEDIUM Unpinned Actions Full Length Commit SHA /release-go.yml: 69 Pinning an action to a full length commit SHA is currently the only way to use an action as an immutable release. Pinning to a particular SHA helps...
MEDIUM Unpinned Actions Full Length Commit SHA /build-cli.yml: 86 Pinning an action to a full length commit SHA is currently the only way to use an action as an immutable release. Pinning to a particular SHA helps...
MEDIUM Unpinned Actions Full Length Commit SHA /publish-java.yml: 99 Pinning an action to a full length commit SHA is currently the only way to use an action as an immutable release. Pinning to a particular SHA helps...
MEDIUM Unpinned Actions Full Length Commit SHA /release-cpp.yml: 59 Pinning an action to a full length commit SHA is currently the only way to use an action as an immutable release. Pinning to a particular SHA helps...
MEDIUM Unpinned Actions Full Length Commit SHA /release-go.yml: 89 Pinning an action to a full length commit SHA is currently the only way to use an action as an immutable release. Pinning to a particular SHA helps...
MEDIUM Unpinned Actions Full Length Commit SHA /publish-napi.yml: 111 Pinning an action to a full length commit SHA is currently the only way to use an action as an immutable release. Pinning to a particular SHA helps...
MEDIUM Unpinned Actions Full Length Commit SHA /release-wasm.yml: 43 Pinning an action to a full length commit SHA is currently the only way to use an action as an immutable release. Pinning to a particular SHA helps...
MEDIUM Unpinned Actions Full Length Commit SHA /build-ruby.yml: 25 Pinning an action to a full length commit SHA is currently the only way to use an action as an immutable release. Pinning to a particular SHA helps...
MEDIUM Unpinned Actions Full Length Commit SHA /release-cpp.yml: 65 Pinning an action to a full length commit SHA is currently the only way to use an action as an immutable release. Pinning to a particular SHA helps...
MEDIUM Unpinned Actions Full Length Commit SHA /build-swift.yml: 96 Pinning an action to a full length commit SHA is currently the only way to use an action as an immutable release. Pinning to a particular SHA helps...
MEDIUM Unpinned Actions Full Length Commit SHA /publish-java.yml: 83 Pinning an action to a full length commit SHA is currently the only way to use an action as an immutable release. Pinning to a particular SHA helps...
MEDIUM Unpinned Actions Full Length Commit SHA /publish-bws.yml: 169 Pinning an action to a full length commit SHA is currently the only way to use an action as an immutable release. Pinning to a particular SHA helps...
MEDIUM Unpinned Actions Full Length Commit SHA /build-cli.yml: 173 Pinning an action to a full length commit SHA is currently the only way to use an action as an immutable release. Pinning to a particular SHA helps...
MEDIUM Unpinned Actions Full Length Commit SHA /release-swift.yml: 137 Pinning an action to a full length commit SHA is currently the only way to use an action as an immutable release. Pinning to a particular SHA helps...
MEDIUM Unpinned Actions Full Length Commit SHA /release-bws.yml: 44 Pinning an action to a full length commit SHA is currently the only way to use an action as an immutable release. Pinning to a particular SHA helps...
MEDIUM Unpinned Actions Full Length Commit SHA /publish-dotnet.yml: 88 Pinning an action to a full length commit SHA is currently the only way to use an action as an immutable release. Pinning to a particular SHA helps...
MEDIUM Unpinned Actions Full Length Commit SHA /version-bump.yml: 54 Pinning an action to a full length commit SHA is currently the only way to use an action as an immutable release. Pinning to a particular SHA helps...
MEDIUM Unpinned Actions Full Length Commit SHA /publish-bws.yml: 163 Pinning an action to a full length commit SHA is currently the only way to use an action as an immutable release. Pinning to a particular SHA helps...
MEDIUM Unpinned Actions Full Length Commit SHA /release-napi.yml: 45 Pinning an action to a full length commit SHA is currently the only way to use an action as an immutable release. Pinning to a particular SHA helps...
MEDIUM Unpinned Actions Full Length Commit SHA /release-bws.yml: 52 Pinning an action to a full length commit SHA is currently the only way to use an action as an immutable release. Pinning to a particular SHA helps...
MEDIUM Unpinned Actions Full Length Commit SHA /release-dotnet.yml: 54 Pinning an action to a full length commit SHA is currently the only way to use an action as an immutable release. Pinning to a particular SHA helps...

Copy link

codecov bot commented Oct 7, 2024

Codecov Report

Attention: Patch coverage is 0% with 43 lines in your changes missing coverage. Please review.

Project coverage is 58.18%. Comparing base (43e5ae9) to head (fe72f34).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
crates/bitwarden-wasm-internal/src/crypto.rs 0.00% 10 Missing ⚠️
...rates/bitwarden-wasm-internal/src/vault/folders.rs 0.00% 7 Missing ⚠️
crates/bitwarden-wasm-internal/src/vault/mod.rs 0.00% 7 Missing ⚠️
crates/bitwarden-wasm-internal/src/client.rs 0.00% 6 Missing ⚠️
crates/bitwarden-wasm-internal/src/error.rs 0.00% 6 Missing ⚠️
crates/bitwarden-core/src/mobile/crypto.rs 0.00% 4 Missing ⚠️
crates/bitwarden-vault/src/folder.rs 0.00% 2 Missing ⚠️
crates/bitwarden-crypto/src/keys/master_key.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1116      +/-   ##
==========================================
- Coverage   58.34%   58.18%   -0.17%     
==========================================
  Files         193      197       +4     
  Lines       13541    13584      +43     
==========================================
+ Hits         7901     7904       +3     
- Misses       5640     5680      +40     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@coroiu coroiu force-pushed the PM-11764-implement-account-switching-and-sdk-initialization branch from 08e889d to e23e30b Compare October 10, 2024 07:35
I really shouldn't need to be fixing this
@coroiu coroiu force-pushed the PM-11764-implement-account-switching-and-sdk-initialization branch from 919c591 to 0105672 Compare October 10, 2024 09:04
@coroiu coroiu marked this pull request as ready for review October 10, 2024 09:15
@coroiu coroiu requested a review from Hinton October 10, 2024 09:18
.editorconfig Outdated Show resolved Hide resolved
crates/bitwarden-wasm-internal/src/crypto.rs Outdated Show resolved Hide resolved
Comment on lines +18 to +22
#[cfg(feature = "wasm")]
#[wasm_bindgen::prelude::wasm_bindgen(typescript_custom_section)]
const TS_CUSTOM_TYPES: &'static str = r#"
export type AsymmetricEncString = string;
"#;
Copy link
Member

Choose a reason for hiding this comment

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

We have a uniffi_support.rs file, would it make sense to add something similar for these custom logics? Or should we encourage lifting in the uniffi logic to where it's needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added custom_types.rs which is inspired by that uniffi file, but I think adding the types where they are defined is a preferred approach. It's just that we sometimes use external type and so I needed both approaches

coroiu and others added 2 commits October 14, 2024 11:56
This change removes any direct dependency on error enums and instead relies on the `ToString` trait to convert any and all errors to strings. A follow-up ticket will have to investigate how we best implement support for catching specific errors
@coroiu coroiu requested review from dani-garcia and Hinton October 14, 2024 10:06
@coroiu
Copy link
Contributor Author

coroiu commented Oct 14, 2024

Adding @dani-garcia as reviewer because @Hinton is traveling/at conference

dani-garcia
dani-garcia previously approved these changes Oct 14, 2024
Copy link
Member

@dani-garcia dani-garcia left a comment

Choose a reason for hiding this comment

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

LGTM!

@@ -6,6 +6,8 @@ use bitwarden_crypto::{
};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
#[cfg(feature = "wasm")]
use {tsify_next::Tsify, wasm_bindgen::prelude::*};
Copy link
Member

Choose a reason for hiding this comment

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

Huh, I just discovered now thanks to this that you can use a top level {} block in a use statement, neat!

@@ -27,7 +29,7 @@ fn convert_level(level: LogLevel) -> Level {
// Rc<...> is to avoid needing to take ownership of the Client during our async run_command
// function https://github.com/rustwasm/wasm-bindgen/issues/2195#issuecomment-799588401
#[wasm_bindgen]
pub struct BitwardenClient(Rc<Client>);
pub struct BitwardenClient(pub(crate) Rc<Client>);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
pub struct BitwardenClient(pub(crate) Rc<Client>);
pub struct BitwardenClient(Rc<Client>);

Nit: This inner value is only used on it's own impl as far as I know, so we don't need it to be pub(crate)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's used when creating it, but I can just create a new function instead
image

@coroiu coroiu merged commit a0f4530 into main Oct 14, 2024
99 of 100 checks passed
@coroiu coroiu deleted the PM-11764-implement-account-switching-and-sdk-initialization branch October 14, 2024 12:44
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