@@ -20,6 +20,7 @@ package json_test
2020
2121import (
2222 "context"
23+ encjson "encoding/json"
2324 "os"
2425 "path/filepath"
2526 "sync"
@@ -130,6 +131,41 @@ var _ = Describe("Json", func() {
130131 })
131132 })
132133
134+ Describe ("ListPublicShares" , func () {
135+ It ("skips shares whose persisted resource_id is nil instead of panicking" , func () {
136+ // Create one valid share so the manager has a healthy row to compare against.
137+ validShare , err := m .CreatePublicShare (ctx , user1 , sharedResource , & link.Grant {
138+ Permissions : & link.PublicSharePermissions {
139+ Permissions : & providerv1beta1.ResourcePermissions {},
140+ },
141+ })
142+ Expect (err ).ToNot (HaveOccurred ())
143+
144+ // Inject a corrupt row directly into the persistence file: the share's stored
145+ // JSON has no `resource_id`, so after unmarshal `local.ResourceId` is nil.
146+ // This mirrors the production state described in OCISDEV-862.
147+ raw , err := os .ReadFile (tmpFile .Name ())
148+ Expect (err ).ToNot (HaveOccurred ())
149+
150+ db := map [string ]interface {}{}
151+ Expect (encjson .Unmarshal (raw , & db )).To (Succeed ())
152+
153+ db ["corrupt-share-id" ] = map [string ]interface {}{
154+ "share" : `{"id":{"opaque_id":"corrupt-share-id"},"token":"corrupt-token"}` ,
155+ "password" : "" ,
156+ }
157+ patched , err := encjson .Marshal (db )
158+ Expect (err ).ToNot (HaveOccurred ())
159+ Expect (os .WriteFile (tmpFile .Name (), patched , 0644 )).To (Succeed ())
160+
161+ // Listing must not panic and must return the valid share.
162+ shares , err := m .ListPublicShares (ctx , user1 , []* link.ListPublicSharesRequest_Filter {}, false )
163+ Expect (err ).ToNot (HaveOccurred ())
164+ Expect (len (shares )).To (Equal (1 ))
165+ Expect (shares [0 ].Id .OpaqueId ).To (Equal (validShare .Id .OpaqueId ))
166+ })
167+ })
168+
133169 Describe ("Load" , func () {
134170 It ("loads shares including state and mountpoint information" , func () {
135171 existingShare , err := m .CreatePublicShare (ctx , user1 , sharedResource , & link.Grant {
0 commit comments