Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Version info to ServerAd #1753

Merged
merged 8 commits into from
Dec 11, 2024
147 changes: 147 additions & 0 deletions director/director_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,153 @@ func TestDirectorRegistration(t *testing.T) {
assert.False(t, getAd.DisableDirectorTest)
teardown()
})

t.Run("origin-advertise-with-version-and-ua-test", func(t *testing.T) {
patrickbrophy marked this conversation as resolved.
Show resolved Hide resolved
c, r, w := setupContext()
pKey, token, _ := generateToken()
publicKey, err := jwk.PublicKeyOf(pKey)
assert.NoError(t, err, "Error creating public key from private key")
setupJwksCache(t, "/foo/bar", publicKey)

isurl := url.URL{}
isurl.Path = ts.URL

ad := server_structs.OriginAdvertiseV2{
BrokerURL: "https://broker-url.org",
DataURL: "https://or-url.org",
Name: "test",
Namespaces: []server_structs.NamespaceAdV2{{
Path: "/foo/bar",
Issuer: []server_structs.TokenIssuer{{IssuerUrl: isurl}},
}},
Version: "7.0.0",
}

jsonad, err := json.Marshal(ad)
assert.NoError(t, err, "Error marshalling OriginAdvertise")

setupRequest(c, r, jsonad, token, server_structs.OriginType)

r.ServeHTTP(w, c.Request)

assert.Equal(t, 200, w.Result().StatusCode, "Expected status code of 200")

get := serverAds.Get("https://or-url.org")
getAd := get.Value()
require.NotNil(t, get, "Coudln't find server in the director cache.")
assert.Equal(t, ad.Version, getAd.Version)
teardown()

})
t.Run("origin-advertise-with-ua-version-test", func(t *testing.T) {
c, r, w := setupContext()
pKey, token, _ := generateToken()
publicKey, err := jwk.PublicKeyOf(pKey)
assert.NoError(t, err, "Error creating public key from private key")
setupJwksCache(t, "/foo/bar", publicKey)

isurl := url.URL{}
isurl.Path = ts.URL

ad := server_structs.OriginAdvertiseV2{
BrokerURL: "https://broker-url.org",
DataURL: "https://or-url.org",
Name: "test",
Namespaces: []server_structs.NamespaceAdV2{{
Path: "/foo/bar",
Issuer: []server_structs.TokenIssuer{{IssuerUrl: isurl}},
}},
}

jsonad, err := json.Marshal(ad)
assert.NoError(t, err, "Error marshalling OriginAdvertise")

setupRequest(c, r, jsonad, token, server_structs.OriginType)

r.ServeHTTP(w, c.Request)

assert.Equal(t, 200, w.Result().StatusCode, "Expected status code of 200")

get := serverAds.Get("https://or-url.org")
getAd := get.Value()
require.NotNil(t, get, "Coudln't find server in the director cache.")
assert.Equal(t, "7.0.0", getAd.Version)
teardown()
})

t.Run("origin-advertise-with-no-version-info-test", func(t *testing.T) {
c, r, w := setupContext()
pKey, token, _ := generateToken()
publicKey, err := jwk.PublicKeyOf(pKey)
assert.NoError(t, err, "Error creating public key from private key")
setupJwksCache(t, "/foo/bar", publicKey)

isurl := url.URL{}
isurl.Path = ts.URL

ad := server_structs.OriginAdvertiseV2{
BrokerURL: "https://broker-url.org",
DataURL: "https://or-url.org",
Name: "test",
Namespaces: []server_structs.NamespaceAdV2{{
Path: "/foo/bar",
Issuer: []server_structs.TokenIssuer{{IssuerUrl: isurl}},
}},
}

jsonad, err := json.Marshal(ad)
assert.NoError(t, err, "Error marshalling OriginAdvertise")

setupRequest(c, r, jsonad, token, server_structs.OriginType)
// set header so that it doesn't have any version info
c.Request.Header.Set("User-Agent", "fake-curl")

r.ServeHTTP(w, c.Request)

assert.Equal(t, 200, w.Result().StatusCode, "Expected status code of 200")

get := serverAds.Get("https://or-url.org")
getAd := get.Value()
require.NotNil(t, get, "Coudln't find server in the director cache.")
assert.Equal(t, "unknown", getAd.Version)
teardown()
})

t.Run("origin-advertise-with-old-ad-test", func(t *testing.T) {
c, r, w := setupContext()
pKey, token, _ := generateToken()
publicKey, err := jwk.PublicKeyOf(pKey)
assert.NoError(t, err, "Error creating public key from private key")
setupJwksCache(t, "/foo/bar", publicKey)

isurl := url.URL{}
isurl.Path = ts.URL

ad := server_structs.OriginAdvertiseV1{
Name: "test",
URL: "https://or-url.org",
Namespaces: []server_structs.NamespaceAdV1{{
Path: "/foo/bar",
Issuer: isurl,
}},
}

jsonad, err := json.Marshal(ad)
assert.NoError(t, err, "Error marshalling OriginAdvertise")

setupRequest(c, r, jsonad, token, server_structs.OriginType)

r.ServeHTTP(w, c.Request)

assert.Equal(t, 200, w.Result().StatusCode, "Expected status code of 200")

get := serverAds.Get("https://or-url.org")
getAd := get.Value()
require.NotNil(t, get, "Coudln't find server in the director cache.")
assert.Equal(t, "7.0.0", getAd.Version)
teardown()

})
}

func TestGetAuthzEscaped(t *testing.T) {
Expand Down
Loading