From 11922daf49ee919521bef6da5791aafb13dc5528 Mon Sep 17 00:00:00 2001 From: Alban Crequy Date: Fri, 8 Apr 2016 18:25:14 +0200 Subject: [PATCH] discovery: fix HasPrefix in matching app name The following meta: Should make the following discoverable: actool discover coreos.com/etcd/fdfdsffds:v2.0.10 actool discover coreos.com/etcd:v2.0.10 But not the following: actool discover coreos.com/etcdxxxxxxx:v2.0.10 This is now fixed by checking the character '/' in addition to HasPrefix. Fixes https://github.com/appc/spec/issues/592 --- discovery/discovery.go | 4 +++ discovery/discovery_test.go | 57 ++++++++++++++++++++++++++++++++++ discovery/testdata/meta07.html | 13 ++++++++ 3 files changed, 74 insertions(+) create mode 100644 discovery/testdata/meta07.html diff --git a/discovery/discovery.go b/discovery/discovery.go index b2dc6595..a4b0b7d6 100644 --- a/discovery/discovery.go +++ b/discovery/discovery.go @@ -148,6 +148,10 @@ func doDiscover(pre string, hostHeaders map[string]http.Header, app App, insecur if !strings.HasPrefix(app.Name.String(), m.prefix) { continue } + if len(app.Name.String()) > len(m.prefix) && + app.Name.String()[len(m.prefix)] != '/' { + continue + } switch m.name { case "ac-discovery": diff --git a/discovery/discovery_test.go b/discovery/discovery_test.go index bb2ca254..2a6cfd70 100644 --- a/discovery/discovery_test.go +++ b/discovery/discovery_test.go @@ -531,6 +531,63 @@ func TestDiscoverEndpoints(t *testing.T) { []string{"https://example.com/pubkeys.gpg"}, testAuthHeader, }, + + // Test for https://github.com/appc/spec/issues/592 + { + &mockHTTPDoer{ + doer: fakeHTTPGet( + []meta{ + {"", + "meta07.html", + }, + }, + nil, + ), + }, + true, + true, + App{ + Name: "example.com/myapp", + Labels: map[types.ACIdentifier]string{ + "version": "1.0.0", + "os": "linux", + "arch": "amd64", + }, + }, + []ACIEndpoint{ + ACIEndpoint{ + ACI: "https://storage.example.com/myapp-1.0.0-linux-amd64.aci", + ASC: "https://storage.example.com/myapp-1.0.0-linux-amd64.aci.asc", + }, + }, + []string{"https://example.com/pubkeys.gpg"}, + nil, + }, + { + &mockHTTPDoer{ + doer: fakeHTTPGet( + []meta{ + {"", + "meta07.html", + }, + }, + nil, + ), + }, + false, + false, + App{ + Name: "example.com/myappandothers", + Labels: map[types.ACIdentifier]string{ + "version": "1.0.0", + "os": "linux", + "arch": "amd64", + }, + }, + nil, + nil, + nil, + }, } for i, tt := range tests { diff --git a/discovery/testdata/meta07.html b/discovery/testdata/meta07.html new file mode 100644 index 00000000..a9b0b800 --- /dev/null +++ b/discovery/testdata/meta07.html @@ -0,0 +1,13 @@ + + + + + My app + + + + + +

My App

+ +