Scille / parsec-cloud

Open source Dropbox-like file sharing with full client encryption !
https://parsec.cloud
Other
272 stars 40 forks source link

Always use `invalid` TLD in tests to avoid possible unexpected request #8808

Open touilleMan opened 1 month ago

touilleMan commented 1 month ago

See https://github.com/Scille/parsec-cloud/pull/8585#discussion_r1816575530

Don't use a real address if we don't plan on actually reaching it (otherwise this can lead to unexpected things if our code is buggy and the url is actually accessed)

Instead you should use the .invalid top level domain that is a reserved TLD for this kind of needs, so typically parsec3://parsec.invalid/Org?... (also note we don't need no_ssl=true)

Currently 83 URLs in tests are not using the .invalid TLD, so I guess we should correct them:

$ grep --color=always -R 'parsec3://' libparsec/crates/*/tests | grep -v invalid | wc -l
libparsec/crates/types/tests/unit/addr.rs:    |outcome| { p_assert_eq!(outcome, Ok("parsec3://example.com".parse().unwrap())); },
libparsec/crates/types/tests/unit/addr.rs:    |outcome| { p_assert_eq!(outcome, Ok("parsec3://example.com?no_ssl=true".parse().unwrap())); },
libparsec/crates/types/tests/unit/addr.rs:    |outcome| { p_assert_eq!(outcome, Ok("parsec3://example.com".parse().unwrap())); },
libparsec/crates/types/tests/unit/addr.rs:    |outcome| { p_assert_eq!(outcome, Ok("parsec3://example.com".parse().unwrap())); },
libparsec/crates/types/tests/unit/addr.rs:    "parsec3://example.com/foo/",
libparsec/crates/types/tests/unit/addr.rs:    "parsec3://example.com",
libparsec/crates/types/tests/unit/addr.rs:    "parsec3://example.com",
libparsec/crates/types/tests/unit/addr.rs:#[case::root_path("parsec3://example.com", Some("/"), "https://example.com/")]
libparsec/crates/types/tests/unit/addr.rs:#[case::empty_path("parsec3://example.com", Some(""), "https://example.com/")]
libparsec/crates/types/tests/unit/addr.rs:#[case::no_path("parsec3://example.com", None, "https://example.com/")]
libparsec/crates/types/tests/unit/addr.rs:    "parsec3://192.168.1.1:4242",
libparsec/crates/types/tests/unit/addr.rs:#[case::no_ssl("parsec3://example.com?no_ssl=true", None, "http://example.com/")]
libparsec/crates/types/tests/unit/addr.rs:#[case::no_ssl_false("parsec3://example.com:443?no_ssl=false", None, "https://example.com/")]
libparsec/crates/types/tests/unit/addr.rs:    "parsec3://example.com:4242?no_ssl=true",
libparsec/crates/types/tests/unit/addr.rs:    "parsec3://example.com:80?no_ssl=true",
libparsec/crates/types/tests/unit/addr.rs:#[case::default_port("parsec3://example.com:443", None, "https://example.com/")]
libparsec/crates/types/tests/unit/addr.rs:#[case::non_default_port("parsec3://example.com:80", None, "https://example.com:80/")]
libparsec/crates/types/tests/unit/addr.rs:    "parsec3://example.com",
libparsec/crates/types/tests/unit/addr.rs:    "parsec3://example.com",
libparsec/crates/types/tests/unit/addr.rs:            Some(extra) => format!("parsec3://?{}", extra),
libparsec/crates/types/tests/unit/addr.rs:            None => "parsec3://".to_string(),
libparsec/crates/types/tests/unit/addr.rs:        "parsec3://example.com",
libparsec/crates/types/tests/unit/addr.rs:        "parsec3://example.com?no_ssl=false",
libparsec/crates/types/tests/unit/addr.rs:        "parsec3://example.com",
libparsec/crates/types/tests/unit/addr.rs:        "parsec3://example.com?no_ssl=true",
libparsec/crates/types/tests/unit/addr.rs:        "parsec3://parsec.example.com/my_org?a=path&p=k9gCLU3tEnQGRgiDO39X8BFW4gHcADTM4WfM1MzhzNnMvTPMq8y-BnrM-8yiDcyvdlvMv2wjzIskB8zZWi4yFwRtzMxAzIDM0iPMnX8czKY7Pm3M5szoODd-NiI8U3A",  // cspell:disable-line
libparsec/crates/types/tests/unit/addr.rs:        "parsec3://parsec.example.com/my_org?a=path&no_ssl=true&p=k9gCLU3tEnQGRgiDO39X8BFW4gHcADTM4WfM1MzhzNnMvTPMq8y-BnrM-8yiDcyvdlvMv2wjzIskB8zZWi4yFwRtzMxAzIDM0iPMnX8czKY7Pm3M5szoODd-NiI8U3A",  // cspell:disable-line
libparsec/crates/types/tests/unit/addr.rs:        "parsec3://parsec.example.com/my_org?no_ssl=true&a=path&p=k9gCLU3tEnQGRgiDO39X8BFW4gHcADTM4WfM1MzhzNnMvTPMq8y-BnrM-8yiDcyvdlvMv2wjzIskB8zZWi4yFwRtzMxAzIDM0iPMnX8czKY7Pm3M5szoODd-NiI8U3A",  // cspell:disable-line
libparsec/crates/types/tests/unit/addr.rs:#[case("parsec3://foo.bar/redirection/my_org")]
libparsec/crates/types/tests/unit/addr.rs:#[case("parsec3://foo", 443, true)]
libparsec/crates/types/tests/unit/addr.rs:#[case("parsec3://foo?no_ssl=false", 443, true)]
libparsec/crates/types/tests/unit/addr.rs:#[case("parsec3://foo?no_ssl=true", 80, false)]
libparsec/crates/types/tests/unit/addr.rs:#[case("parsec3://foo:42", 42, true)]
libparsec/crates/types/tests/unit/addr.rs:#[case("parsec3://foo:42?dummy=", 42, true)]
libparsec/crates/types/tests/unit/addr.rs:#[case("parsec3://foo:42?no_ssl=true", 42, false)]
libparsec/crates/types/tests/unit/addr.rs:#[case("parsec3://foo:42?no_ssl=false&dummy=foo", 42, true)]
libparsec/crates/types/tests/unit/addr.rs:#[case::path_not_allowed("parsec3://foo:42/dummy", AddrError::ShouldNotHaveAPath)]
libparsec/crates/types/tests/unit/addr.rs:    "parsec3://foo:42?no_ssl",
libparsec/crates/types/tests/unit/addr.rs:    "parsec3://foo:42?no_ssl=",
libparsec/crates/types/tests/unit/addr.rs:    "parsec3://foo:42?no_ssl=nop",
libparsec/crates/types/tests/unit/addr.rs:#[case("parsec3://foo", 443, true)]
libparsec/crates/types/tests/unit/addr.rs:#[case("parsec3://foo?no_ssl=false", 443, true)]
libparsec/crates/types/tests/unit/addr.rs:#[case("parsec3://foo?no_ssl=true", 80, false)]
libparsec/crates/types/tests/unit/addr.rs:#[case("parsec3://foo:42", 42, true)]
libparsec/crates/types/tests/unit/addr.rs:#[case("parsec3://foo:42?dummy=", 42, true)]
libparsec/crates/types/tests/unit/addr.rs:#[case("parsec3://foo:42?no_ssl=true", 42, false)]
libparsec/crates/types/tests/unit/addr.rs:#[case("parsec3://foo:42?no_ssl=false", 42, true)]
libparsec/crates/types/tests/unit/addr.rs:#[case("parsec3://foo:42?no_ssl=false&dummy=foo", 42, true)]
libparsec/crates/types/tests/unit/addr.rs:    "parsec3://foo:42?p=xCBs8zpdIwovR8EdliVVo2vUOmtumnfsI6Fdndjm0WconA",
libparsec/crates/types/tests/unit/addr.rs:    "parsec3://foo:42/?p=xCBs8zpdIwovR8EdliVVo2vUOmtumnfsI6Fdndjm0WconA",
libparsec/crates/types/tests/unit/addr.rs:    "parsec3://foo:42/bad/org?p=xCBs8zpdIwovR8EdliVVo2vUOmtumnfsI6Fdndjm0WconA",
libparsec/crates/types/tests/unit/addr.rs:    "parsec3://foo:42/~org?p=xCBs8zpdIwovR8EdliVVo2vUOmtumnfsI6Fdndjm0WconA",
libparsec/crates/types/tests/unit/addr.rs:    "parsec3://foo:42/org?p=dummy",
libparsec/crates/types/tests/unit/addr.rs:    "parsec3://foo:42/org?p=ZHVtbXk",
libparsec/crates/types/tests/unit/addr.rs:    "parsec3://foo:42/org?p=xAA",
libparsec/crates/types/tests/unit/addr.rs:    "parsec3://foo:42/org?p=xAEA",
libparsec/crates/types/tests/unit/addr.rs:#[case("parsec3://foo", 443, true)]
libparsec/crates/types/tests/unit/addr.rs:#[case("parsec3://foo?no_ssl=false", 443, true)]
libparsec/crates/types/tests/unit/addr.rs:#[case("parsec3://foo?no_ssl=true", 80, false)]
libparsec/crates/types/tests/unit/addr.rs:#[case("parsec3://foo:42", 42, true)]
libparsec/crates/types/tests/unit/addr.rs:#[case("parsec3://foo:42?dummy=foo", 42, true)]
libparsec/crates/types/tests/unit/addr.rs:#[case("parsec3://foo:42?no_ssl=true", 42, false)]
libparsec/crates/types/tests/unit/addr.rs:#[case("parsec3://foo:42?no_ssl=true&dummy=", 42, false)]
libparsec/crates/types/tests/unit/addr.rs:#[case("parsec3://foo:42?no_ssl=false", 42, true)]
libparsec/crates/types/tests/unit/addr.rs:#[case::missing_action("parsec3://foo:42/org?p=wA", AddrError::MissingParam("a"))]
libparsec/crates/types/tests/unit/addr.rs:    "parsec3://foo:42/org?a=bootstrap_organization",
libparsec/crates/types/tests/unit/addr.rs:    "parsec3://foo:42/org?a=dummy&p=wA",
libparsec/crates/types/tests/unit/addr.rs:    "parsec3://foo:42/org?a=bootstrap_organization&p=dummy",
libparsec/crates/types/tests/unit/addr.rs:    "parsec3://foo:42/org?a=bootstrap_organization&p=ZHVtbXk",
libparsec/crates/types/tests/unit/addr.rs:    "parsec3://foo:42/org?a=bootstrap_organization&p=xAA",
libparsec/crates/types/tests/unit/addr.rs:    "parsec3://foo:42/org?a=bootstrap_organization&p=xAEA",
libparsec/crates/types/tests/unit/addr.rs:    "parsec3://foo:42?a=bootstrap_organization&p=wA",
libparsec/crates/types/tests/unit/addr.rs:    "parsec3://foo:42/?a=bootstrap_organization&p=wA",
libparsec/crates/types/tests/unit/addr.rs:    "parsec3://foo:42/bad/org?a=bootstrap_organization&p=wA",
libparsec/crates/types/tests/unit/addr.rs:    "parsec3://foo:42/~org?a=bootstrap_organization&p=wA",
libparsec/crates/types/tests/unit/addr.rs:    "parsec3://parsec.example.com/my_org?a=bootstrap_organization&p=xBCgAAAAAAAAAAAAAAAAAAAB",
libparsec/crates/types/tests/unit/addr.rs:    "parsec3://parsec.example.com/my_org?a=path&p=k9gCLU3tEnQGRgiDO39X8BFW4gHcADTM4WfM1MzhzNnMvTPMq8y-BnrM-8yiDcyvdlvMv2wjzIskB8zZWi4yFwRtzMxAzIDM0iPMnX8czKY7Pm3M5szoODd-NiI8U3A",
libparsec/crates/types/tests/unit/addr.rs:    "parsec3://parsec.example.com/my_org?a=claim_user&p=xBCgAAAAAAAAAAAAAAAAAAAB",
libparsec/crates/types/tests/unit/addr.rs:    "parsec3://parsec.example.com/my_org?a=pki_enrollment",
libparsec/crates/types/tests/unit/addr.rs:#[case::missing_param("parsec3://parsec.example.com/my_org?a=claim_user")]
libparsec/crates/types/tests/unit/local_device.rs:        organization_addr: "parsec3://alice_dev1.example.com:9999/CoolOrg?no_ssl=true&p=xCC-KXZzLOyMqU7tzwqv1BPNFZNj4PrcnmhXLHeh4X2bvQ".parse().unwrap(),
libparsec/crates/types/tests/unit/pki.rs:                "parsec3://parsec.example.com/my_org?a=pki_enrollment",
libparsec/crates/types/tests/unit/pki.rs:                "parsec3://parsec.example.com/my_org?a=pki_enrollment",
AureliaDolo commented 1 month ago

We could left the example.com https://www.iana.org/help/example-domains

But better be consistent.