Skip to content

Commit

Permalink
Added tests for tracking if the version was properly registered
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickbrophy committed Dec 6, 2024
1 parent 5c65cf3 commit 428d9f2
Showing 1 changed file with 147 additions and 0 deletions.
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) {
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

0 comments on commit 428d9f2

Please sign in to comment.