@@ -10,6 +10,7 @@ import (
1010 "path/filepath"
1111 "reflect"
1212 "regexp"
13+ "slices"
1314 "sort"
1415 "strings"
1516 "testing"
@@ -246,18 +247,22 @@ func TestOpenAPI_SplitFields(t *testing.T) {
246247
247248func TestOpenAPI_SpecialPaths (t * testing.T ) {
248249 tests := map [string ]struct {
249- pattern string
250- rootPaths []string
251- rootExpected bool
252- unauthenticatedPaths []string
253- unauthenticatedExpected bool
250+ pattern string
251+ rootPaths []string
252+ rootExpected bool
253+ unauthenticatedPaths []string
254+ unauthenticatedExpected bool
255+ allowSnapshotRead []string
256+ allowSnapshotReadExpected bool
254257 }{
255258 "empty" : {
256- pattern : "foo" ,
257- rootPaths : []string {},
258- rootExpected : false ,
259- unauthenticatedPaths : []string {},
260- unauthenticatedExpected : false ,
259+ pattern : "foo" ,
260+ rootPaths : []string {},
261+ rootExpected : false ,
262+ unauthenticatedPaths : []string {},
263+ unauthenticatedExpected : false ,
264+ allowSnapshotRead : []string {},
265+ allowSnapshotReadExpected : false ,
261266 },
262267 "exact-match-unauthenticated" : {
263268 pattern : "foo" ,
@@ -336,17 +341,75 @@ func TestOpenAPI_SpecialPaths(t *testing.T) {
336341 unauthenticatedPaths : []string {"foo/bar" },
337342 unauthenticatedExpected : false ,
338343 },
344+ "exact-match-snapshot-read" : {
345+ pattern : "foo" ,
346+ rootPaths : []string {},
347+ rootExpected : false ,
348+ unauthenticatedPaths : []string {},
349+ unauthenticatedExpected : false ,
350+ allowSnapshotRead : []string {"foo" },
351+ allowSnapshotReadExpected : true ,
352+ },
353+ "asterisk-match-snapshot-read" : {
354+ pattern : "foo/bar" ,
355+ rootPaths : []string {},
356+ rootExpected : false ,
357+ unauthenticatedPaths : []string {},
358+ unauthenticatedExpected : false ,
359+ allowSnapshotRead : []string {"foo/*" },
360+ allowSnapshotReadExpected : true ,
361+ },
362+ "no-match-snapshot-read" : {
363+ pattern : "foo/bar" ,
364+ rootPaths : []string {},
365+ rootExpected : false ,
366+ unauthenticatedPaths : []string {},
367+ unauthenticatedExpected : false ,
368+ allowSnapshotRead : []string {"baz" },
369+ allowSnapshotReadExpected : false ,
370+ },
371+ "multiple-snapshot-read-paths" : {
372+ pattern : "foo/bar" ,
373+ rootPaths : []string {},
374+ rootExpected : false ,
375+ unauthenticatedPaths : []string {},
376+ unauthenticatedExpected : false ,
377+ allowSnapshotRead : []string {"foo/*" , "baz" },
378+ allowSnapshotReadExpected : true ,
379+ },
380+ "plus-match-snapshot-read" : {
381+ pattern : "foo/bar/baz" ,
382+ rootPaths : []string {},
383+ rootExpected : false ,
384+ unauthenticatedPaths : []string {},
385+ unauthenticatedExpected : false ,
386+ allowSnapshotRead : []string {"foo/+/baz" },
387+ allowSnapshotReadExpected : true ,
388+ },
389+ "plus-and-asterisk-snapshot-read" : {
390+ pattern : "foo/bar/baz/something" ,
391+ rootPaths : []string {},
392+ rootExpected : false ,
393+ unauthenticatedPaths : []string {},
394+ unauthenticatedExpected : false ,
395+ allowSnapshotRead : []string {"foo/+/baz/*" },
396+ allowSnapshotReadExpected : true ,
397+ },
339398 }
340399 for name , test := range tests {
341400 t .Run (name , func (t * testing.T ) {
342401 doc := NewOASDocument ("version" )
343402 path := Path {
344403 Pattern : test .pattern ,
404+ Operations : map [logical.Operation ]OperationHandler {
405+ logical .ReadOperation : & PathOperation {},
406+ },
345407 }
346408 backend := & Backend {
347409 PathsSpecial : & logical.Paths {
348- Root : test .rootPaths ,
349- Unauthenticated : test .unauthenticatedPaths ,
410+ Root : test .rootPaths ,
411+ Unauthenticated : test .unauthenticatedPaths ,
412+ AllowSnapshotRead : test .allowSnapshotRead ,
350413 },
351414 BackendType : logical .TypeLogical ,
352415 }
@@ -364,6 +427,16 @@ func TestOpenAPI_SpecialPaths(t *testing.T) {
364427 if actual != test .unauthenticatedExpected {
365428 t .Fatalf ("Test (unauth): expected: %v; got: %v" , test .unauthenticatedExpected , actual )
366429 }
430+
431+ var supportsSnapshotId bool
432+ if doc .Paths ["/" + test .pattern ].Get != nil {
433+ supportsSnapshotId = slices .ContainsFunc (doc .Paths ["/" + test .pattern ].Get .Parameters , func (p OASParameter ) bool {
434+ return p .Name == "read_snapshot_id"
435+ })
436+ }
437+ if supportsSnapshotId != test .allowSnapshotReadExpected {
438+ t .Fatalf ("Test (allowSnapshotRead): expected: %v; got: %v" , test .allowSnapshotReadExpected , actual )
439+ }
367440 })
368441 }
369442}
@@ -475,14 +548,18 @@ func TestOpenAPI_Paths(t *testing.T) {
475548 Summary : "This shouldn't show up" ,
476549 Unpublished : true ,
477550 },
551+ logical .RecoverOperation : & PathOperation {
552+ Summary : "Recover Summary shouldn't show up" ,
553+ },
478554 },
479555 DisplayAttrs : & DisplayAttributes {
480556 Navigation : true ,
481557 },
482558 }
483559
484560 sp := & logical.Paths {
485- Root : []string {"foo*" },
561+ Root : []string {"foo*" },
562+ AllowSnapshotRead : []string {"*" },
486563 }
487564 testPath (t , p , sp , expected ("operations" ))
488565 })
@@ -930,19 +1007,6 @@ func testPath(t *testing.T, path *Path, sp *logical.Paths, expectedJSON string)
9301007 }
9311008}
9321009
933- func getPathOp (pi * OASPathItem , op string ) * OASOperation {
934- switch op {
935- case "get" :
936- return pi .Get
937- case "post" :
938- return pi .Post
939- case "delete" :
940- return pi .Delete
941- default :
942- panic ("unexpected operation: " + op )
943- }
944- }
945-
9461010func expected (name string ) string {
9471011 data , err := ioutil .ReadFile (filepath .Join ("testdata" , name + ".json" ))
9481012 if err != nil {
0 commit comments