summaryrefslogtreecommitdiffstats
path: root/vendor/gix-credentials/tests/protocol/context.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-19 09:26:03 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-19 09:26:03 +0000
commit9918693037dce8aa4bb6f08741b6812923486c18 (patch)
tree21d2b40bec7e6a7ea664acee056eb3d08e15a1cf /vendor/gix-credentials/tests/protocol/context.rs
parentReleasing progress-linux version 1.75.0+dfsg1-5~progress7.99u1. (diff)
downloadrustc-9918693037dce8aa4bb6f08741b6812923486c18.tar.xz
rustc-9918693037dce8aa4bb6f08741b6812923486c18.zip
Merging upstream version 1.76.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/gix-credentials/tests/protocol/context.rs')
-rw-r--r--vendor/gix-credentials/tests/protocol/context.rs175
1 files changed, 0 insertions, 175 deletions
diff --git a/vendor/gix-credentials/tests/protocol/context.rs b/vendor/gix-credentials/tests/protocol/context.rs
deleted file mode 100644
index 3cfd850a3..000000000
--- a/vendor/gix-credentials/tests/protocol/context.rs
+++ /dev/null
@@ -1,175 +0,0 @@
-mod destructure_url_in_place {
- use gix_credentials::protocol::Context;
-
- fn url_ctx(url: &str) -> Context {
- Context {
- url: Some(url.into()),
- ..Default::default()
- }
- }
-
- fn assert_eq_parts(
- url: &str,
- proto: &str,
- user: impl Into<Option<&'static str>>,
- host: &str,
- path: impl Into<Option<&'static str>>,
- use_http_path: bool,
- ) {
- let mut ctx = url_ctx(url);
- ctx.destructure_url_in_place(use_http_path).expect("splitting works");
- assert_eq!(ctx.protocol.expect("set proto"), proto);
- match user.into() {
- Some(expected) => assert_eq!(ctx.username.expect("set user"), expected),
- None => assert!(ctx.username.is_none()),
- }
- assert_eq!(ctx.host.expect("set host"), host);
- match path.into() {
- Some(expected) => assert_eq!(ctx.path.expect("set path"), expected),
- None => assert!(ctx.path.is_none()),
- }
- }
-
- #[test]
- fn parts_are_verbatim_with_non_http_url() {
- // path is always used for non-http
- assert_eq_parts("ssh://user@host:21/path", "ssh", "user", "host:21", "path", false);
- assert_eq_parts("ssh://host.org/path", "ssh", None, "host.org", "path", true);
- }
- #[test]
- fn http_and_https_ignore_the_path_by_default() {
- assert_eq_parts(
- "http://user@example.com/path",
- "http",
- Some("user"),
- "example.com",
- None,
- false,
- );
- assert_eq_parts(
- "https://github.com/byron/gitoxide",
- "https",
- None,
- "github.com",
- None,
- false,
- );
- assert_eq_parts(
- "https://github.com/byron/gitoxide/",
- "https",
- None,
- "github.com",
- "byron/gitoxide",
- true,
- );
- }
-}
-
-mod to_prompt {
- use gix_credentials::protocol::Context;
-
- #[test]
- fn no_scheme_means_no_url() {
- assert_eq!(Context::default().to_prompt("Username"), "Username: ");
- }
-
- #[test]
- fn any_scheme_means_url_is_included() {
- assert_eq!(
- Context {
- protocol: Some("https".into()),
- host: Some("host".into()),
- ..Default::default()
- }
- .to_prompt("Password"),
- "Password for https://host: "
- );
- }
-}
-
-mod to_url {
- use gix_credentials::protocol::Context;
-
- #[test]
- fn no_protocol_is_nothing() {
- assert_eq!(Context::default().to_url(), None);
- }
- #[test]
- fn protocol_alone_is_enough() {
- assert_eq!(
- Context {
- protocol: Some("https".into()),
- ..Default::default()
- }
- .to_url()
- .unwrap(),
- "https://"
- );
- }
- #[test]
- fn username_is_appended() {
- assert_eq!(
- Context {
- protocol: Some("https".into()),
- username: Some("user".into()),
- ..Default::default()
- }
- .to_url()
- .unwrap(),
- "https://user@"
- );
- }
- #[test]
- fn host_is_appended() {
- assert_eq!(
- Context {
- protocol: Some("https".into()),
- host: Some("host".into()),
- ..Default::default()
- }
- .to_url()
- .unwrap(),
- "https://host"
- );
- }
- #[test]
- fn path_is_appended_with_leading_slash_placed_as_needed() {
- assert_eq!(
- Context {
- protocol: Some("file".into()),
- path: Some("dir/git".into()),
- ..Default::default()
- }
- .to_url()
- .unwrap(),
- "file:///dir/git"
- );
- assert_eq!(
- Context {
- protocol: Some("file".into()),
- path: Some("/dir/git".into()),
- ..Default::default()
- }
- .to_url()
- .unwrap(),
- "file:///dir/git"
- );
- }
-
- #[test]
- fn all_fields_with_port_but_password_is_never_shown() {
- assert_eq!(
- Context {
- protocol: Some("https".into()),
- username: Some("user".into()),
- password: Some("secret".into()),
- host: Some("example.com:8080".into()),
- path: Some("Byron/gitoxide".into()),
- ..Default::default()
- }
- .to_url()
- .unwrap(),
- "https://user@example.com:8080/Byron/gitoxide"
- );
- }
-}