Repository navigation
Prompt user for credentials when http request needs it - #34620
Conversation
|
cc @jdm I asked a few questions about how to deal with errors in the comments. |
|
@jdm since this feature is about prompting users for authentication, are we assuming that the user will always be asked for a |
Yes, we will only need to prompt for username and password. |
6319034 to
dbd1a23
Compare
|
@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. |
| http_request | ||
| .current_url_mut() | ||
| .set_username(&username) | ||
| .unwrap(); |
There was a problem hiding this comment.
how should an error be handled here? Log and return response?
There was a problem hiding this comment.
I've added error handling, let me know if there is any other data that should be logged
5670a41 to
57ac38c
Compare
| } | ||
| } | ||
|
|
||
| fn create_embedder_proxy_and_receiver() -> (EmbedderProxy, EmbedderReceiver) { |
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
But yes, I think multiple prompts are the desired outcome here.
Edit: I now see that |
|
@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 |
a7c97d6 to
d627c95
Compare
| sender.send(cb.prompt_input(message, default, trusted)) | ||
| }, | ||
| PromptDefinition::Credentials(_) => { | ||
| warn!("implement credentials prompt for open harmony OS"); |
There was a problem hiding this comment.
@jdm should I use the todo!() macro instead of a warning?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
yeah that makes sense, regarding todo!(). Would it be worth marking PromptDefinition non-exhaustive now?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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]>
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]>
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]>
Signed-off-by: Lloyd Massiah <[email protected]>
Signed-off-by: Lloyd Massiah <[email protected]>
cad36ae to
720a017
Compare
Signed-off-by: Lloyd Massiah <[email protected]>
Signed-off-by: Lloyd Massiah <[email protected]>
|
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 |
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). |
Oh nice, that will save me a lot of trouble in the future. Thanks |
| proxy.send(( | ||
| None, | ||
| EmbedderMsg::Prompt( | ||
| PromptDefinition::Credentials(ipc_sender), | ||
| PromptOrigin::Trusted, | ||
| ), | ||
| )); |
There was a problem hiding this comment.
This should contain the ID of the browsing context. Otherwise, the embedder has no idea where it comes from.
This adds two prompts that will ask the user for their username and password if a http request requires it.
./mach build -ddoes not report any errors./mach test-tidydoes not report any errors