Skip to content

Prompt user for credentials when http request needs it - #34620

Merged
jdm merged 13 commits into
servo:mainfrom
arthmis:lmassiah/issue-27439
Dec 28, 2024
Merged

jdm merged 13 commits into
servo:mainfrom
arthmis:lmassiah/issue-27439

Conversation

@arthmis

@arthmis arthmis commented Dec 14, 2024 •

Copy link
Copy Markdown
Contributor

This adds two prompts that will ask the user for their username and password if a http request requires it.


  • There are tests for these changes OR
  • These changes do not require tests because ___

@arthmis

arthmis commented Dec 14, 2024

Copy link
Copy Markdown
Contributor Author

cc @jdm I asked a few questions about how to deal with errors in the comments.

Comment thread components/net/http_loader.rs Resolved
Comment thread components/net/http_loader.rs Resolved
Comment thread components/net/http_loader.rs Resolved
Comment thread components/net/http_loader.rs Resolved
Comment thread components/net/http_loader.rs Resolved
Comment thread components/net/http_loader.rs Resolved
Comment thread components/net/tests/main.rs Resolved
@arthmis

arthmis commented Dec 15, 2024 •

Copy link
Copy Markdown
Contributor Author

@jdm since this feature is about prompting users for authentication, are we assuming that the user will always be asked for a username and password? Is it possible to be asked for maybe single inputs like a authentication key or something like that? I looked here and it seems including credentials always means username and password. Is that understanding correct?

Comment thread components/net/http_loader.rs Resolved
@jdm

jdm commented Dec 15, 2024

Copy link
Copy Markdown
Member

@jdm since this feature is about prompting users for authentication, are we assuming that the user will always be asked for a username and password? Is it possible to be asked for maybe single inputs like a authentication key or something like that? I looked here and it seems including credentials always means username and password. Is that understanding correct?

Yes, we will only need to prompt for username and password.

@arthmis
arthmis force-pushed the lmassiah/issue-27439 branch from 6319034 to dbd1a23 Compare December 15, 2024 17:28
@arthmis
arthmis marked this pull request as ready for review December 15, 2024 17:33
@arthmis
arthmis requested a review from atbrakhi as a code owner December 15, 2024 17:33
@arthmis

arthmis commented Dec 15, 2024 •

Copy link
Copy Markdown
Contributor Author

@jdm do these particular changes need tests considering that they are only a part of the broader http request functionality?

And are there ways to provide localized strings during the prompts?

Aside from that, I think this is ready for review

@jdm

jdm commented Dec 16, 2024

Copy link
Copy Markdown
Member

@jdm do these particular changes need tests considering that they are only a part of the broader http request functionality?

And are there ways to provide localized strings during the prompts?

Aside from that, I think this is ready for review

Yes, I believe this is not covered by the web-platform-tests because it involves user-agent interactions, so a unit test would be helpful here.

As for localized strings, we don't have a solution for that in servoshell at this time, so we can leave the hardcoded strings.

@jdm jdm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looking good!

Comment thread components/net/http_loader.rs Resolved
Comment thread components/net/http_loader.rs Resolved
Comment thread components/net/http_loader.rs Resolved
Comment thread components/shared/net/lib.rs Resolved
Comment thread components/net/http_loader.rs Outdated
http_request
.current_url_mut()
.set_username(&username)
.unwrap();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

how should an error be handled here? Log and return response?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think that's reasonable.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've added error handling, let me know if there is any other data that should be logged

Comment thread components/net/http_loader.rs Resolved
Comment thread components/net/tests/main.rs Resolved
@arthmis
arthmis force-pushed the lmassiah/issue-27439 branch from 5670a41 to 57ac38c Compare December 20, 2024 16:47
}
}

fn create_embedder_proxy_and_receiver() -> (EmbedderProxy, EmbedderReceiver) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

this has some duplication with the function right above called create_embedder_proxy. I decided not to merge them but I'm open to doing so if you think it's better that way.

}

#[test]
fn test_prompt_credentials_user_input_incorrect_credentials() {

@arthmis arthmis Dec 20, 2024 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

should this test case cause an infinite loop? I was expecting an infinite loop, but that didn't happen, because if the user makes the request with the wrong credentials, the user should be prompted again for credentials? Is that right?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I believe that's because we pass true for the is_authentication_fetch argument when starting the next fetch, and we don't promo the user when that flag is true.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

But yes, I think multiple prompts are the desired outcome here.

@arthmis

arthmis commented Dec 27, 2024 •

Copy link
Copy Markdown
Contributor Author
error[E0004]: non-exhaustive patterns: `PromptDefinition::Credentials(_)` not covered
   --> ports/servoshell/egl/servo_glue.rs:501:37
    |
501 |                     let res = match definition {
    |                                     ^^^^^^^^^^ pattern `PromptDefinition::Credentials(_)` not covered
    |
note: `PromptDefinition` defined here
   --> /home/runner/work/servo/servo/components/shared/embedder/lib.rs:125:1
    |
125 | pub enum PromptDefinition {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^
...
135 |     Credentials(IpcSender<PromptCredentialsInput>),
    |     ----------- not covered
    = note: the matched value is of type `PromptDefinition`
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
    |
514 ~                         },
515 ~                         PromptDefinition::Credentials(_) => todo!(),

Oh wow, how did you end up running into that error?

Edit: I now see that ports/servoshell isn't being discovered as a member of the workspace by rust analyzer because that particular file is only available on android.

@arthmis

arthmis commented Dec 27, 2024 •

Copy link
Copy Markdown
Contributor Author

@jdm So it seems to download the dev tools for Open Harmony OS I need to have a huawei account. So i can't build locally to test changes. I've implemented the skeleton for it so building would pass but I can't confirm it's fine until the CI tries it

@arthmis
arthmis requested a review from jschwe as a code owner December 27, 2024 18:24
@arthmis
arthmis force-pushed the lmassiah/issue-27439 branch from a7c97d6 to d627c95 Compare December 27, 2024 18:26
Comment thread ports/servoshell/egl/servo_glue.rs Outdated
sender.send(cb.prompt_input(message, default, trusted))
},
PromptDefinition::Credentials(_) => {
warn!("implement credentials prompt for open harmony OS");

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@jdm should I use the todo!() macro instead of a warning?

@simonwuelker simonwuelker Dec 27, 2024 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

todo!() would cause servo to crash on ohos when a credential prompt is requested, that is definitely undesirable. A warning is perfectly fine I think.

In the future we should mark enums exposed for the embedding API as #[non_exhaustive] to avoid breaking servoshell and other embedders in cases like this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yeah that makes sense, regarding todo!(). Would it be worth marking PromptDefinition non-exhaustive now?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Would it be worth marking PromptDefinition non-exhaustive now?

I think it would be better to do that in a separate PR as it's unrelated to this one.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Note: This code is shared and used by both OpenHarmony and Android, so probably the warning message should reflect that.
Both currently don't support prompts, so just issuing a warning is perfectly fine for this PR.

arthmis and others added 11 commits December 28, 2024 11:32
Signed-off-by: Lloyd Massiah [email protected]

move credential prompt to a function

Signed-off-by: Lloyd Massiah <[email protected]>
Signed-off-by: Lloyd Massiah <[email protected]>
…embedder_proxy non-optional

- default implementation was only used in tests so created an alternative create_http_state function

Signed-off-by: Lloyd Massiah <[email protected]>

add credentials to authentication cache

Signed-off-by: Lloyd Massiah <[email protected]>
…s, and refactor shared code between tests

Signed-off-by: Lloyd Massiah <[email protected]>
…ting

Signed-off-by: Lloyd Massiah <[email protected]>

renaming test functions

Signed-off-by: Lloyd Massiah <[email protected]>
…c doesn't specify that the flag should be true, and the flag is by default false

Signed-off-by: Lloyd Massiah <[email protected]>
Signed-off-by: Lloyd Massiah <[email protected]>
@arthmis
arthmis force-pushed the lmassiah/issue-27439 branch from cad36ae to 720a017 Compare December 28, 2024 16:32
@jdm
jdm added this pull request to the merge queue Dec 28, 2024
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Dec 28, 2024
@arthmis

arthmis commented Dec 28, 2024

Copy link
Copy Markdown
Contributor Author

ok so second time this failed, I'll try and get the android environment running so I can actually run a build for android and that should allow me to get proper checking. I did add a Ok(()) in the PromptCredentials branch which should fix the issue, and I fixed the unused import warning.

@simonwuelker

Copy link
Copy Markdown
Member

ok so second time this failed, I'll try and get the android environment running so I can actually run a build for android and that should allow me to get proper checking. I did add a Ok(()) in the PromptCredentials branch which should fix the issue, and I fixed the unused import warning.

Alternatively, you can run the android/ohos CI on your fork. (Not ideal, but easier than setting up android if you're not going to work on it in the future).
Under the "Actions" tab, choose the OpenHarmony workflow and start it manually.

@arthmis

arthmis commented Dec 28, 2024 •

Copy link
Copy Markdown
Contributor Author

Alternatively, you can run the android/ohos CI on your fork. (Not ideal, but easier than setting up android if you're not going to work on it in the future). Under the "Actions" tab, choose the OpenHarmony workflow and start it manually.

Oh nice, that will save me a lot of trouble in the future. Thanks

@jdm
jdm added this pull request to the merge queue Dec 28, 2024
Merged via the queue into servo:main with commit aa40b8f Dec 28, 2024
Comment on lines +1770 to +1776
proxy.send((
None,
EmbedderMsg::Prompt(
PromptDefinition::Credentials(ipc_sender),
PromptOrigin::Trusted,
),
));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This should contain the ID of the browsing context. Otherwise, the embedder has no idea where it comes from.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could you open an issue?

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.

Prompt user for authentication when HTTP request needs it

7 participants