Skip to content

Commit

Permalink
Added test for miss matched version. Adjusted logic to handle mismatch
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickbrophy committed Dec 9, 2024
1 parent 428d9f2 commit d302ae6
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
5 changes: 4 additions & 1 deletion director/director.go
Original file line number Diff line number Diff line change
Expand Up @@ -1143,10 +1143,13 @@ func registerServeAd(engineCtx context.Context, ctx *gin.Context, sType server_s
if adV2.Version == "" && reqVer != nil {
adV2.Version = reqVer.String()
} else if adV2.Version != "" && reqVer != nil {
_, err := version.NewVersion(adV2.Version)
parsedAdVersion, err := version.NewVersion(adV2.Version)
if err != nil {
// ad version was not a valid version, so we fallback to the request version
adV2.Version = reqVer.String()
} else if !parsedAdVersion.Equal(reqVer) {
// if the reqVer doesn't match the adV2.version, we should use the adV2.version
adV2.Version = parsedAdVersion.String()
}
} else if adV2.Version == "" {
adV2.Version = "unknown"
Expand Down
40 changes: 40 additions & 0 deletions director/director_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1021,6 +1021,46 @@ func TestDirectorRegistration(t *testing.T) {
teardown()

})

t.Run("origin-advertise-with-mismatch-versions", 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)

// 7.0.1 != 7.0.0
c.Request.Header.Set("User-Agent", "pelican-origin/7.0.1")

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 d302ae6

Please sign in to comment.