| 1 | package managedproxy |
| 2 | |
| 3 | import "testing" |
| 4 | |
| 5 | func TestEndpointAloneCannotAuthorizeNetworking(t *testing.T) { |
| 6 | profile := t.TempDir() |
| 7 | p, _ := Load(profile) |
| 8 | if _, err := Applied(profile, "socks5://127.0.0.1:17896", ""); err == nil { |
| 9 | t.Fatal("old endpoint accepted without nodes") |
| 10 | } |
| 11 | if err := p.Import("qa", "", []byte(`proxies: [{name: qa, type: socks5, server: 127.0.0.1, port: 1080}]`), "qa", 0, ""); err != nil { |
| 12 | t.Fatal(err) |
| 13 | } |
| 14 | p.Revision = "applied" |
| 15 | p.Selected = p.Sources[0].Nodes[0].ID |
| 16 | if err := p.Save(profile); err != nil { |
| 17 | t.Fatal(err) |
| 18 | } |
| 19 | for _, input := range [][2]string{{p.Endpoint(), ""}, {p.Endpoint(), "old"}, {"socks5://127.0.0.1:7890", p.Revision}} { |
| 20 | if _, err := Applied(profile, input[0], input[1]); err == nil { |
| 21 | t.Fatal("unapplied endpoint accepted") |
| 22 | } |
| 23 | } |
| 24 | if _, err := Applied(profile, p.Endpoint(), p.Revision); err != nil { |
| 25 | t.Fatal(err) |
| 26 | } |
| 27 | p.Selected = "" |
| 28 | _ = p.Save(profile) |
| 29 | if _, err := Applied(profile, p.Endpoint(), p.Revision); err == nil { |
| 30 | t.Fatal("removed node retained networking authorization") |
| 31 | } |
| 32 | } |