Skip to content
This repository has been archived by the owner on Apr 20, 2021. It is now read-only.

Commit

Permalink
discovery: fix HasPrefix in matching app name
Browse files Browse the repository at this point in the history
The following meta:
  <meta name="ac-discovery" content="coreos.com/etcd https://github.com/coreos/etcd/releases/download/{version}/etcd-{version}-{os}-{arch}.{ext}">

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 appc#592
  • Loading branch information
alban committed Apr 8, 2016
1 parent 80ab01d commit 11922da
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 0 deletions.
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>

0 comments on commit 11922da

Please sign in to comment.