From 61c90a96506b504ff2033761c9106f616603392a Mon Sep 17 00:00:00 2001 From: Simon Chow Date: Thu, 18 Jan 2024 12:50:36 -0500 Subject: [PATCH 1/2] Pass user agent to archive config in captive core backend --- ingest/ledgerbackend/captive_core_backend.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ingest/ledgerbackend/captive_core_backend.go b/ingest/ledgerbackend/captive_core_backend.go index a8acb19182..ce8da8f8cd 100644 --- a/ingest/ledgerbackend/captive_core_backend.go +++ b/ingest/ledgerbackend/captive_core_backend.go @@ -179,7 +179,8 @@ func NewCaptive(config CaptiveCoreConfig) (*CaptiveStellarCore, error) { NetworkPassphrase: config.NetworkPassphrase, CheckpointFrequency: config.CheckpointFrequency, ConnectOptions: storage.ConnectOptions{ - Context: config.Context, + Context: config.Context, + UserAgent: config.UserAgent, }, }, ) From a234e650898c0b7dc56b9101a8cdb845d84734e0 Mon Sep 17 00:00:00 2001 From: Simon Chow Date: Thu, 18 Jan 2024 14:09:05 -0500 Subject: [PATCH 2/2] Add useragent test for archive pool --- historyarchive/archive_pool_test.go | 39 +++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 historyarchive/archive_pool_test.go diff --git a/historyarchive/archive_pool_test.go b/historyarchive/archive_pool_test.go new file mode 100644 index 0000000000..9f51fd75e3 --- /dev/null +++ b/historyarchive/archive_pool_test.go @@ -0,0 +1,39 @@ +// Copyright 2016 Stellar Development Foundation and contributors. Licensed +// under the Apache License, Version 2.0. See the COPYING file at the root +// of this distribution or at http://www.apache.org/licenses/LICENSE-2.0 + +package historyarchive + +import ( + "net/http" + "net/http/httptest" + "testing" + + "github.com/stellar/go/support/storage" + "github.com/stretchr/testify/assert" +) + +func TestConfiguresHttpUserAgentForArchivePool(t *testing.T) { + var userAgent string + var archiveURLs []string + server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + userAgent = r.Header["User-Agent"][0] + w.WriteHeader(http.StatusOK) + })) + defer server.Close() + archiveURLs = append(archiveURLs, server.URL) + + archiveOptions := ArchiveOptions{ + ConnectOptions: storage.ConnectOptions{ + UserAgent: "uatest", + }, + } + + archivePool, err := NewArchivePool(archiveURLs, archiveOptions) + assert.NoError(t, err) + + ok, err := archivePool.BucketExists(EmptyXdrArrayHash()) + assert.True(t, ok) + assert.NoError(t, err) + assert.Equal(t, userAgent, "uatest") +}