Skip to content

Commit 0fea378

Browse files
committed
feat: update the realyer with the authentication logic
Signed-off-by: rmeena840 <rmeena840@gmail.com>
1 parent bd1da51 commit 0fea378

5 files changed

Lines changed: 12 additions & 11 deletions

File tree

.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ BTC_RPC_USER="user"
1616
BTC_RPC_PASS="pass"
1717
BTC_RPC="localhost:18334"
1818

19-
BEARER_TOKEN=""
19+
NATIVE_BTCINDEXER_BEARER_TOKEN=""

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ Check out [SECURITY.md](./SECURITY.md) for security concerns.
5959

6060
1. Make sure you have `go`, `make` installed
6161
2. Copy and update your env file: `cp .env.example .env`
62-
3. Build the project: `make build`
62+
3. Update the env variables like NATIVE_BTCINDEXER_BEARER_TOKEN etc
63+
4. Build the project: `make build`
6364

6465
To build and start you can run: `make build start`
6566

native/fetcher.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ func (f *APISignRequestFetcher) GetBtcSignRequests(from, limit int) ([]SignReq,
3535
return nil, fmt.Errorf("failed to create request: %w", err)
3636
}
3737

38-
token := os.Getenv("BEARER_TOKEN")
38+
token := os.Getenv("NATIVE_BTCINDEXER_BEARER_TOKEN")
3939
if token == "" {
40-
return nil, fmt.Errorf("BEARER_TOKEN environment variable not set")
40+
return nil, fmt.Errorf("NATIVE_BTCINDEXER_BEARER_TOKEN environment variable not set")
4141
}
4242
req.Header.Set("Authorization", "Bearer "+token)
4343
resp, err := http.DefaultClient.Do(req)

native/fetcher_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func TestAPISignRequestFetcher_GetBtcSignRequests(t *testing.T) {
2727
}
2828

2929
t.Run("Valid request", func(t *testing.T) {
30-
t.Setenv("BEARER_TOKEN", mockToken)
30+
t.Setenv("NATIVE_BTCINDEXER_BEARER_TOKEN", mockToken)
3131
requests, err := fetcher.GetBtcSignRequests(0, 3)
3232
assert.NilError(t, err)
3333
assert.Equal(t, 3, len(requests))
@@ -39,20 +39,20 @@ func TestAPISignRequestFetcher_GetBtcSignRequests(t *testing.T) {
3939
})
4040

4141
t.Run("Invalid API URL", func(t *testing.T) {
42-
t.Setenv("BEARER_TOKEN", mockToken)
42+
t.Setenv("NATIVE_BTCINDEXER_BEARER_TOKEN", mockToken)
4343
fetcher.APIURL = "invalid-url"
4444
_, err := fetcher.GetBtcSignRequests(0, 3)
4545
assert.ErrorContains(t, err, "failed to make API request")
4646
})
4747

4848
t.Run("Missing Env Var error", func(t *testing.T) {
49-
t.Setenv("BEARER_TOKEN", "")
49+
t.Setenv("NATIVE_BTCINDEXER_BEARER_TOKEN", "")
5050
_, err := fetcher.GetBtcSignRequests(0, 3)
51-
assert.ErrorContains(t, err, "BEARER_TOKEN environment variable not set")
51+
assert.ErrorContains(t, err, "NATIVE_BTCINDEXER_BEARER_TOKEN environment variable not set")
5252
})
5353

5454
t.Run("API request failure (500)", func(t *testing.T) {
55-
t.Setenv("BEARER_TOKEN", mockToken)
55+
t.Setenv("NATIVE_BTCINDEXER_BEARER_TOKEN", mockToken)
5656
failTs := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
5757
w.WriteHeader(http.StatusInternalServerError)
5858
}))
@@ -64,7 +64,7 @@ func TestAPISignRequestFetcher_GetBtcSignRequests(t *testing.T) {
6464
})
6565

6666
t.Run("API request failure", func(t *testing.T) {
67-
t.Setenv("BEARER_TOKEN", mockToken)
67+
t.Setenv("NATIVE_BTCINDEXER_BEARER_TOKEN", mockToken)
6868
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
6969
w.WriteHeader(http.StatusInternalServerError)
7070
}))

nbtc/relayer_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ var relayerConfig = RelayerConfig{
4545
// setupTestProcessor initializes the common dependencies
4646
func setupTestSuite(t *testing.T) *testSuite {
4747
t.Helper()
48-
t.Setenv("BEARER_TOKEN", "mock-token")
48+
t.Setenv("NATIVE_BTCINDEXER_BEARER_TOKEN", "mock-token")
4949

5050
ctx := context.Background()
5151
db := daltest.InitTestDB(ctx, t)

0 commit comments

Comments
 (0)