Skip to content

Commit 09d7729

Browse files
Copilotrickyrombo
andauthored
Normalize address to lowercase in Go, revert lower() from SQL queries
Agent-Logs-Url: https://github.com/AudiusProject/api/sessions/9df9ff3f-61bc-492a-bfde-45791942537c Co-authored-by: rickyrombo <3690498+rickyrombo@users.noreply.github.com>
1 parent 92c0bb0 commit 09d7729

File tree

4 files changed

+84
-6
lines changed

4 files changed

+84
-6
lines changed

api/dbv1/get_developer_apps.sql.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/dbv1/queries/get_developer_apps.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ SELECT
99
FROM developer_apps da
1010
LEFT JOIN oauth_redirect_uris oau ON oau.client_id = da.address
1111
WHERE
12-
(da.user_id = @user_id OR lower(da.address) = lower(@address))
12+
(da.user_id = @user_id OR da.address = @address)
1313
AND da.is_current = true
1414
AND da.is_delete = false
1515
GROUP BY da.address, da.user_id, da.name, da.description, da.image_url, da.created_at
@@ -27,7 +27,7 @@ SELECT
2727
FROM developer_apps
2828
LEFT JOIN grants ON grants.grantee_address = developer_apps.address
2929
WHERE
30-
(grants.user_id = @user_id OR lower(developer_apps.address) = lower(@address))
30+
(grants.user_id = @user_id OR developer_apps.address = @address)
3131
AND grants.is_revoked = false
3232
AND grants.is_current = true
3333
AND developer_apps.is_current = true

api/v1_developer_apps.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ func (app *ApiServer) v1DeveloperApps(c *fiber.Ctx) error {
1818
address = "0x" + address
1919
}
2020

21+
// Normalize address to lowercase to ensure case-insensitive matching
22+
// (addresses in the DB are stored as lowercase)
23+
address = strings.ToLower(address)
24+
2125
developerApps, err := app.queries.GetDeveloperApps(c.Context(), dbv1.GetDeveloperAppsParams{
2226
Address: address,
2327
})

api/v1_developer_apps_test.go

Lines changed: 76 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@ import (
88
"github.com/stretchr/testify/assert"
99
)
1010

11+
const testDeveloperAppAddress = "0x7d7b6b7a97d1deefe3a1ccc5a13c48e8f055e0b6"
12+
1113
func TestGetDeveloperAppsQueries(t *testing.T) {
1214
app := testAppWithFixtures(t)
1315
developerApps, err := app.queries.GetDeveloperApps(t.Context(), dbv1.GetDeveloperAppsParams{
1416
UserID: 1,
1517
})
1618
assert.NoError(t, err)
1719
assert.Len(t, developerApps, 1)
18-
assert.Equal(t, "0x7d7b6b7a97d1deefe3a1ccc5a13c48e8f055e0b6", developerApps[0].Address)
20+
assert.Equal(t, testDeveloperAppAddress, developerApps[0].Address)
1921
// redirect_uris must be an empty slice (not nil) when no URIs are registered
2022
assert.Equal(t, []string{}, developerApps[0].RedirectUris)
2123
}
@@ -26,11 +28,83 @@ func TestGetDeveloperApp(t *testing.T) {
2628
var resp struct {
2729
Data dbv1.GetDeveloperAppsRow
2830
}
29-
status, body := testGet(t, app, "/v1/developer_apps/0x7d7b6b7a97d1deefe3a1ccc5a13c48e8f055e0b6", &resp)
31+
status, body := testGet(t, app, "/v1/developer_apps/"+testDeveloperAppAddress, &resp)
3032
assert.Equal(t, 200, status)
3133
assert.True(t, strings.Contains(string(body), `"user_id":"7eP5n"`))
3234
assert.True(t, strings.Contains(string(body), `"name":"cool app"`))
3335
assert.Equal(t, "cool app", resp.Data.Name)
3436
// redirect_uris must be an empty slice (not nil) when no URIs are registered
3537
assert.Equal(t, []string{}, resp.Data.RedirectUris)
3638
}
39+
40+
func TestGetDeveloperAppUppercaseAddress(t *testing.T) {
41+
app := testAppWithFixtures(t)
42+
43+
var resp struct {
44+
Data dbv1.GetDeveloperAppsRow
45+
}
46+
// Uppercase address should still find the app (case-insensitive lookup)
47+
status, _ := testGet(t, app, "/v1/developer_apps/0x7D7B6B7A97D1DEEFE3A1CCC5A13C48E8F055E0B6", &resp)
48+
assert.Equal(t, 200, status)
49+
assert.Equal(t, "cool app", resp.Data.Name)
50+
}
51+
52+
func TestGetDeveloperAppMixedCaseAddress(t *testing.T) {
53+
app := testAppWithFixtures(t)
54+
55+
var resp struct {
56+
Data dbv1.GetDeveloperAppsRow
57+
}
58+
// Mixed-case address should still find the app (case-insensitive lookup)
59+
status, _ := testGet(t, app, "/v1/developer_apps/0x7d7B6B7A97d1deEFe3A1ccc5A13c48E8F055e0B6", &resp)
60+
assert.Equal(t, 200, status)
61+
assert.Equal(t, "cool app", resp.Data.Name)
62+
}
63+
64+
func TestGetDeveloperAppWithoutHexPrefix(t *testing.T) {
65+
app := testAppWithFixtures(t)
66+
67+
var resp struct {
68+
Data dbv1.GetDeveloperAppsRow
69+
}
70+
// Address without 0x prefix should still find the app
71+
status, _ := testGet(t, app, "/v1/developer_apps/7D7B6B7A97D1DEEFE3A1CCC5A13C48E8F055E0B6", &resp)
72+
assert.Equal(t, 200, status)
73+
assert.Equal(t, "cool app", resp.Data.Name)
74+
}
75+
76+
func TestGetDeveloperAppUppercaseAddress(t *testing.T) {
77+
app := testAppWithFixtures(t)
78+
79+
var resp struct {
80+
Data dbv1.GetDeveloperAppsRow
81+
}
82+
// Uppercase address should still find the app (case-insensitive lookup)
83+
status, _ := testGet(t, app, "/v1/developer_apps/0x7D7B6B7A97D1DEEFE3A1CCC5A13C48E8F055E0B6", &resp)
84+
assert.Equal(t, 200, status)
85+
assert.Equal(t, "cool app", resp.Data.Name)
86+
}
87+
88+
func TestGetDeveloperAppMixedCaseAddress(t *testing.T) {
89+
app := testAppWithFixtures(t)
90+
91+
var resp struct {
92+
Data dbv1.GetDeveloperAppsRow
93+
}
94+
// Mixed-case address should still find the app (case-insensitive lookup)
95+
status, _ := testGet(t, app, "/v1/developer_apps/0x7d7B6B7A97d1deEFe3A1ccc5A13c48E8F055e0B6", &resp)
96+
assert.Equal(t, 200, status)
97+
assert.Equal(t, "cool app", resp.Data.Name)
98+
}
99+
100+
func TestGetDeveloperAppWithoutHexPrefix(t *testing.T) {
101+
app := testAppWithFixtures(t)
102+
103+
var resp struct {
104+
Data dbv1.GetDeveloperAppsRow
105+
}
106+
// Address without 0x prefix should still find the app
107+
status, _ := testGet(t, app, "/v1/developer_apps/7D7B6B7A97D1DEEFE3A1CCC5A13C48E8F055E0B6", &resp)
108+
assert.Equal(t, 200, status)
109+
assert.Equal(t, "cool app", resp.Data.Name)
110+
}

0 commit comments

Comments
 (0)