Skip to content

Commit

Permalink
[api] handle usernames in the format of [email protected]
Browse files Browse the repository at this point in the history
  • Loading branch information
jbygdell committed Aug 7, 2024
1 parent e7fa8cb commit 1cc7ab3
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion sda/cmd/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ func listUserFiles(c *gin.Context) {
username = strings.TrimPrefix(username, "/")
username = strings.TrimSuffix(username, "/files")
log.Debugln(username)
files, err := Conf.API.DB.GetUserFiles(username)
files, err := Conf.API.DB.GetUserFiles(strings.ReplaceAll(username, "@", "_"))
if err != nil {
c.AbortWithStatusJSON(http.StatusInternalServerError, err.Error())

Expand Down
2 changes: 1 addition & 1 deletion sda/cmd/api/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ Admin endpoints are only available to a set of whitelisted users specified in th
Example:
```bash
curl -H "Authorization: Bearer $token" -X GET https://HOSTNAME/users
curl -H "Authorization: Bearer $token" -X GET https://HOSTNAME/users/[email protected]/files
```

- Error codes
Expand Down
6 changes: 3 additions & 3 deletions sda/cmd/api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1135,7 +1135,7 @@ func (suite *TestSuite) TestListActiveUsers() {
}

func (suite *TestSuite) TestListUserFiles() {
testUsers := []string{"User-A", "User-B", "User-C"}
testUsers := []string{"user_example.org", "User-B", "User-C"}
for _, user := range testUsers {
for i := 0; i < 5; i++ {
fileID, err := Conf.API.DB.RegisterFile(fmt.Sprintf("/%v/TestGetUserFiles-00%d.c4gh", user, i), user)
Expand All @@ -1156,7 +1156,7 @@ func (suite *TestSuite) TestListUserFiles() {
}
}

err = Conf.API.DB.MapFilesToDataset("test-dataset-01", []string{"accession_User-A_00", "accession_User-A_01", "accession_User-A_02"})
err = Conf.API.DB.MapFilesToDataset("test-dataset-01", []string{"accession_user_example.org_00", "accession_user_example.org_01", "accession_user_example.org_02"})
if err != nil {
suite.FailNow("failed to map files to dataset")
}
Expand All @@ -1167,7 +1167,7 @@ func (suite *TestSuite) TestListUserFiles() {

// Mock request and response holders
w := httptest.NewRecorder()
r := httptest.NewRequest(http.MethodGet, "/users/User-A/files", http.NoBody)
r := httptest.NewRequest(http.MethodGet, "/users/[email protected]/files", http.NoBody)
r.Header.Add("Authorization", "Bearer "+suite.Token)

_, router := gin.CreateTestContext(w)
Expand Down

0 comments on commit 1cc7ab3

Please sign in to comment.