2016-02-20 21:05:48 +00:00
|
|
|
package rest
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/url"
|
|
|
|
"testing"
|
2023-04-20 21:02:56 +00:00
|
|
|
|
|
|
|
"github.com/restic/restic/internal/backend/test"
|
2016-02-20 21:05:48 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func parseURL(s string) *url.URL {
|
|
|
|
u, err := url.Parse(s)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return u
|
|
|
|
}
|
|
|
|
|
2023-04-20 21:02:56 +00:00
|
|
|
var configTests = []test.ConfigTestData[Config]{
|
2018-03-15 20:37:18 +00:00
|
|
|
{
|
2023-04-20 21:02:56 +00:00
|
|
|
S: "rest:http://localhost:1234",
|
|
|
|
Cfg: Config{
|
2018-03-15 20:37:18 +00:00
|
|
|
URL: parseURL("http://localhost:1234/"),
|
|
|
|
Connections: 5,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2023-04-20 21:02:56 +00:00
|
|
|
S: "rest:http://localhost:1234/",
|
|
|
|
Cfg: Config{
|
2018-03-15 20:37:18 +00:00
|
|
|
URL: parseURL("http://localhost:1234/"),
|
|
|
|
Connections: 5,
|
|
|
|
},
|
|
|
|
},
|
2024-01-29 03:23:56 +00:00
|
|
|
{
|
|
|
|
S: "rest:http+unix:///tmp/rest.socket:/my_backup_repo/",
|
|
|
|
Cfg: Config{
|
|
|
|
URL: parseURL("http+unix:///tmp/rest.socket:/my_backup_repo/"),
|
|
|
|
Connections: 5,
|
|
|
|
},
|
|
|
|
},
|
2016-02-20 21:05:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestParseConfig(t *testing.T) {
|
2023-04-20 21:02:56 +00:00
|
|
|
test.ParseConfigTester(t, ParseConfig, configTests)
|
2016-02-20 21:05:48 +00:00
|
|
|
}
|
2023-06-08 13:17:00 +00:00
|
|
|
|
|
|
|
var passwordTests = []struct {
|
|
|
|
input string
|
|
|
|
expected string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
"rest:",
|
|
|
|
"rest:/",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"rest:localhost/",
|
|
|
|
"rest:localhost/",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"rest::123/",
|
|
|
|
"rest::123/",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"rest:http://",
|
|
|
|
"rest:http://",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"rest:http://hostname.foo:1234/",
|
|
|
|
"rest:http://hostname.foo:1234/",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"rest:http://user@hostname.foo:1234/",
|
|
|
|
"rest:http://user@hostname.foo:1234/",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"rest:http://user:@hostname.foo:1234/",
|
|
|
|
"rest:http://user:***@hostname.foo:1234/",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"rest:http://user:p@hostname.foo:1234/",
|
|
|
|
"rest:http://user:***@hostname.foo:1234/",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"rest:http://user:pppppaaafhhfuuwiiehhthhghhdkjaoowpprooghjjjdhhwuuhgjsjhhfdjhruuhsjsdhhfhshhsppwufhhsjjsjs@hostname.foo:1234/",
|
|
|
|
"rest:http://user:***@hostname.foo:1234/",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"rest:http://user:password@hostname",
|
|
|
|
"rest:http://user:***@hostname/",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"rest:http://user:password@:123",
|
|
|
|
"rest:http://user:***@:123/",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"rest:http://user:password@",
|
|
|
|
"rest:http://user:***@/",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestStripPassword(t *testing.T) {
|
|
|
|
// Make sure that the factory uses the correct method
|
|
|
|
StripPassword := NewFactory().StripPassword
|
|
|
|
|
|
|
|
for i, test := range passwordTests {
|
|
|
|
t.Run(test.input, func(t *testing.T) {
|
|
|
|
result := StripPassword(test.input)
|
|
|
|
if result != test.expected {
|
|
|
|
t.Errorf("test %d: expected '%s' but got '%s'", i, test.expected, result)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|