Skip to content
This repository has been archived by the owner on Aug 14, 2020. It is now read-only.

discovery: fix HasPrefix in matching app name #594

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions discovery/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
57 changes: 57 additions & 0 deletions discovery/discovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
13 changes: 13 additions & 0 deletions discovery/testdata/meta07.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>

<html>
<head>
<title>My app</title>
<meta name="ac-discovery" content="example.com/myapp https://storage.example.com/myapp-{version}-{os}-{arch}.{ext}">
<meta name="ac-discovery-pubkeys" content="example.com https://example.com/pubkeys.gpg">
</head>

<body>
<h1>My App</h1>
</body>
</html>