Skip to content

Conversation

@mariobodemann
Copy link
Collaborator

@mariobodemann mariobodemann commented Dec 3, 2025

While testing the wrapper we found that the initial implementation needed some more love.

This PR fixes cruicial local container creation, and adds love.

Use correct encoding and creation of clientDataJson
@mariobodemann
Copy link
Collaborator Author

Executing the test locally (revolutionary concept):

JS bridge error. expected:<"[]"> but was:<"[Exception: {\"message\":\"Failed to set the 'innerHTML' property on 'Element': This document requires 'TrustedHTML' assignment.\"}]">
at org.junit.Assert.assertEquals(Assert.java:117)
at com.yubico.ykbrowser.StartUpTest.javascriptInjectionIsCorrect(StartUpTest.kt:91)

I.e. someone from the maintainers (@tladesignz, or @jessevanmuijden maybe?) need to see how to fix the frontend requiring TrustedHTML in combination with adding the debug icon to the dom.

Good luck.

Comment on lines +146 to +150
if (secureStore.containsAlias(alias)) {
secureStore.deleteEntry(alias)
} else {
failureCallback(IllegalStateException("Credential alias nor found."))
}

Choose a reason for hiding this comment

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

Suggested change
if (secureStore.containsAlias(alias)) {
secureStore.deleteEntry(alias)
} else {
failureCallback(IllegalStateException("Credential alias nor found."))
}
if (!secureStore.containsAlias(alias)) {
failureCallback(IllegalStateException("Credential alias nor found."))
}
secureStore.deleteEntry(alias)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I am not sure about this one: It looks like you'd always delete an entry, if it exists or not.

(Also just noticed a typo in the original code: nor should probably be not.)

Comment on lines +152 to +161
if (filename !in context.fileList()) {
// no delete necessary
failureCallback(IllegalStateException("File $filename not found."))
} else {
if (context.deleteFile(filename)) {
successCallback()
} else {
failureCallback(RuntimeException("Failed to delete $filename file."))
}
}

Choose a reason for hiding this comment

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

Suggested change
if (filename !in context.fileList()) {
// no delete necessary
failureCallback(IllegalStateException("File $filename not found."))
} else {
if (context.deleteFile(filename)) {
successCallback()
} else {
failureCallback(RuntimeException("Failed to delete $filename file."))
}
}
if (filename !in context.fileList()) {
// no delete necessary
failureCallback(IllegalStateException("File $filename not found."))
}
if (!context.deleteFile(filename)) {
failureCallback(RuntimeException("Failed to delete $filename file."))
}
successCallback()

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

🤔

Wouldn't that open the possibility to call the failureCallback() and then the successCallback() when the file doesn't exist.

Also the failure callback would get invoked twice if the file doesn't exist: First on check, and then when the non existant file is tried to get deleted...

The idea for me is that there shouldn't be an option where both callbacks can get called (or one callback gets called multiple times).

Copy link
Collaborator Author

@mariobodemann mariobodemann left a comment

Choose a reason for hiding this comment

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

I am not sure if I get the intent of the proposed changes. See inline for detailed feedback.

Comment on lines +152 to +161
if (filename !in context.fileList()) {
// no delete necessary
failureCallback(IllegalStateException("File $filename not found."))
} else {
if (context.deleteFile(filename)) {
successCallback()
} else {
failureCallback(RuntimeException("Failed to delete $filename file."))
}
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

🤔

Wouldn't that open the possibility to call the failureCallback() and then the successCallback() when the file doesn't exist.

Also the failure callback would get invoked twice if the file doesn't exist: First on check, and then when the non existant file is tried to get deleted...

The idea for me is that there shouldn't be an option where both callbacks can get called (or one callback gets called multiple times).

Comment on lines +146 to +150
if (secureStore.containsAlias(alias)) {
secureStore.deleteEntry(alias)
} else {
failureCallback(IllegalStateException("Credential alias nor found."))
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I am not sure about this one: It looks like you'd always delete an entry, if it exists or not.

(Also just noticed a typo in the original code: nor should probably be not.)

@jessevanmuijden
Copy link

@mariobodemann the proposed changes were just a suggestion to replace nested if statements with early returns for readability.

@mariobodemann
Copy link
Collaborator Author

Ah, I get the intent.

But that wouldn't work. In your suggestions you'll call the callbacks but you aren't exiting the function.

You'd need an explicit return, or nested ifs with the right value returned.

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