@@ -73,14 +73,14 @@ func generateTestData() {
7373 Id : idApiKeyAdmin ,
7474 PublicId : idApiKeyAdmin ,
7575 FriendlyName : "Admin" ,
76- Permissions : models .ApiPermAll ,
76+ Permissions : models .ApiPermNone ,
7777 UserId : idAdmin ,
7878 })
7979 database .SaveApiKey (models.ApiKey {
8080 Id : idApiKeySuperAdmin ,
8181 PublicId : idPublicApiKeySuperAdmin ,
8282 FriendlyName : "SuperAdmin" ,
83- Permissions : models .ApiPermAll ,
83+ Permissions : models .ApiPermNone ,
8484 UserId : idSuperAdmin ,
8585 })
8686 database .SaveMetaData (models.File {
@@ -120,7 +120,6 @@ func getRecorderWithBody(url, apikey, method string, headers []test.Header, body
120120}
121121
122122func testAuthorisation (t * testing.T , url string , requiredPermission models.ApiPermission ) models.ApiKey {
123- t .Helper ()
124123 w , r := getRecorder (url , "" , []test.Header {{}})
125124 Process (w , r )
126125 test .IsEqualBool (t , w .Code != 200 , true )
@@ -131,13 +130,13 @@ func testAuthorisation(t *testing.T, url string, requiredPermission models.ApiPe
131130 test .IsEqualBool (t , w .Code != 200 , true )
132131 test .ResponseBodyContains (t , w , `{"Result":"error","ErrorMessage":"Unauthorized"}` )
133132
134- newApiKeyUser := generateNewKey (false , idUser , "" )
133+ newApiKeyUser := generateNewKey (false , idUser , "" , "" )
135134 w , r = getRecorder (url , newApiKeyUser .Id , []test.Header {{}})
136135 Process (w , r )
137136 test .IsEqualBool (t , w .Code != 200 , true )
138137 test .ResponseBodyContains (t , w , `{"Result":"error","ErrorMessage":"Unauthorized"}` )
139138
140- for _ , permission := range getAvailableApiPermissions (t ) {
139+ for _ , permission := range getAvailableApiPermissions () {
141140 if permission == requiredPermission {
142141 continue
143142 }
@@ -148,7 +147,7 @@ func testAuthorisation(t *testing.T, url string, requiredPermission models.ApiPe
148147 test .ResponseBodyContains (t , w , `{"Result":"error","ErrorMessage":"Unauthorized"}` )
149148 removePermissionApikey (t , newApiKeyUser .Id , permission )
150149 }
151- newApiKeyUser .Permissions = models . ApiPermAll
150+ newApiKeyUser .Permissions = getPermissionAll ()
152151 newApiKeyUser .RemovePermission (requiredPermission )
153152 database .SaveApiKey (newApiKeyUser )
154153 w , r = getRecorder (url , newApiKeyUser .Id , []test.Header {{}})
@@ -432,7 +431,7 @@ func testDeleteUserCall(t *testing.T, apiKey string, mode int) {
432431 database .SaveSession ("sessionApiDelete" , session )
433432 _ , ok = database .GetSession ("sessionApiDelete" )
434433 test .IsEqualBool (t , ok , true )
435- userApiKey := generateNewKey (false , retrievedUser .Id , "" )
434+ userApiKey := generateNewKey (false , retrievedUser .Id , "" , "" )
436435 _ , ok = database .GetApiKey (userApiKey .Id )
437436 test .IsEqualBool (t , ok , true )
438437 testFile := models.File {
@@ -699,16 +698,16 @@ func TestIsValidApiKey(t *testing.T) {
699698 test .IsEqualBool (t , ok , true )
700699 test .IsEqualBool (t , key .LastUsed == 0 , false )
701700
702- newApiKey := generateNewKey (false , 5 , "" )
701+ newApiKey := generateNewKey (false , 5 , "" , "" )
703702 user , _ , isValid = isValidApiKey (newApiKey .Id , true , models .ApiPermNone )
704703 test .IsEqualBool (t , isValid , true )
705- for _ , permission := range getAvailableApiPermissions (t ) {
704+ for _ , permission := range getAvailableApiPermissions () {
706705 _ , _ , isValid = isValidApiKey (newApiKey .Id , true , permission )
707706 test .IsEqualBool (t , isValid , false )
708707 }
709- for _ , newPermission := range getAvailableApiPermissions (t ) {
708+ for _ , newPermission := range getAvailableApiPermissions () {
710709 setPermissionApikey (t , newApiKey .Id , newPermission )
711- for _ , permission := range getAvailableApiPermissions (t ) {
710+ for _ , permission := range getAvailableApiPermissions () {
712711 _ , _ , isValid = isValidApiKey (newApiKey .Id , true , permission )
713712 test .IsEqualBool (t , isValid , permission == newPermission )
714713 }
@@ -717,7 +716,7 @@ func TestIsValidApiKey(t *testing.T) {
717716 setPermissionApikey (t , newApiKey .Id , models .ApiPermEdit | models .ApiPermDelete )
718717 _ , _ , isValid = isValidApiKey (newApiKey .Id , true , models .ApiPermEdit )
719718 test .IsEqualBool (t , isValid , true )
720- _ , _ , isValid = isValidApiKey (newApiKey .Id , true , models . ApiPermAll )
719+ _ , _ , isValid = isValidApiKey (newApiKey .Id , true , getPermissionAll () )
721720 test .IsEqualBool (t , isValid , false )
722721 _ , _ , isValid = isValidApiKey (newApiKey .Id , true , models .ApiPermView )
723722 test .IsEqualBool (t , isValid , false )
@@ -736,7 +735,7 @@ func removePermissionApikey(t *testing.T, key string, newPermission models.ApiPe
736735 database .SaveApiKey (apiKey )
737736}
738737
739- func getAvailableApiPermissions (t * testing. T ) []models.ApiPermission {
738+ func getAvailableApiPermissions () []models.ApiPermission {
740739 result := []models.ApiPermission {
741740 models .ApiPermView ,
742741 models .ApiPermUpload ,
@@ -745,17 +744,21 @@ func getAvailableApiPermissions(t *testing.T) []models.ApiPermission {
745744 models .ApiPermEdit ,
746745 models .ApiPermReplace ,
747746 models .ApiPermManageUsers ,
748- models .ApiPermManageLogs }
749- sum := 0
750- for _ , perm := range result {
751- sum = sum + int (perm )
752- }
753- if sum != int (models .ApiPermAll ) {
754- t .Fatal ("List of permissions are incorrect" )
747+ models .ApiPermManageLogs ,
748+ models .ApiPermManageFileRequests ,
749+ models .ApiPermDownload ,
755750 }
756751 return result
757752}
758753
754+ func getPermissionAll () models.ApiPermission {
755+ allPermissions := models .ApiPermNone
756+ for _ , permission := range getAvailableApiPermissions () {
757+ allPermissions += permission
758+ }
759+ return allPermissions
760+ }
761+
759762func getApiPermMap (t * testing.T ) map [models.ApiPermission ]string {
760763 result := make (map [models.ApiPermission ]string )
761764 result [models .ApiPermView ] = "PERM_VIEW"
@@ -766,12 +769,14 @@ func getApiPermMap(t *testing.T) map[models.ApiPermission]string {
766769 result [models .ApiPermReplace ] = "PERM_REPLACE"
767770 result [models .ApiPermManageUsers ] = "PERM_MANAGE_USERS"
768771 result [models .ApiPermManageLogs ] = "PERM_MANAGE_LOGS"
772+ result [models .ApiPermManageFileRequests ] = "PERM_MANAGE_FILE_REQUESTS"
773+ result [models .ApiPermDownload ] = "PERM_DOWNLOAD"
769774
770775 sum := 0
771776 for perm := range result {
772777 sum = sum + int (perm )
773778 }
774- if sum != int (models . ApiPermAll ) {
779+ if sum != int (getPermissionAll () ) {
775780 t .Fatal ("List of permissions are incorrect" )
776781 }
777782
@@ -1291,7 +1296,7 @@ func uploadNewFile(t *testing.T) (models.Result, *bytes.Buffer) {
12911296 test .IsNil (t , err )
12921297 err = writer .Close ()
12931298 test .IsNil (t , err )
1294- newApiKeyUser := generateNewKey (true , idUser , "" )
1299+ newApiKeyUser := generateNewKey (true , idUser , "" , "" )
12951300 w , r := test .GetRecorder ("POST" , "/api/files/add" , nil , []test.Header {{
12961301 Name : "apikey" ,
12971302 Value : newApiKeyUser .Id ,
0 commit comments