Skip to content

Commit 6ad7dc9

Browse files
SAPRD2daveshanley
authored andcommitted
increased coverage
1 parent 3f579cc commit 6ad7dc9

File tree

4 files changed

+79
-4
lines changed

4 files changed

+79
-4
lines changed

helpers/regex_maker.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func GetRegexForPath(tpl string) (*regexp.Regexp, error) {
1818
template := tpl
1919

2020
// Now let's parse it.
21-
defaultPattern := "[^/]+"
21+
defaultPattern := "[^/]*"
2222

2323
pattern := bytes.NewBufferString("^")
2424
var end int

helpers/regex_maker_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ func TestGetRegexForPath(t *testing.T) {
1515
name: "well-formed template with default pattern",
1616
tpl: "/orders/{id}",
1717
wantErr: false,
18-
wantExpr: "^/orders/([^/]+)$",
18+
wantExpr: "^/orders/([^/]*)$",
1919
},
2020
{
2121
name: "well-formed template with custom pattern",
@@ -47,13 +47,13 @@ func TestGetRegexForPath(t *testing.T) {
4747
name: "template with multiple variables",
4848
tpl: "/orders/{id:[0-9]+}/items/{itemId}",
4949
wantErr: false,
50-
wantExpr: "^/orders/([0-9]+)/items/([^/]+)$",
50+
wantExpr: "^/orders/([0-9]+)/items/([^/]*)$",
5151
},
5252
{
5353
name: "OData formatted URL with single quotes",
5454
tpl: "/entities('{id}')",
5555
wantErr: false,
56-
wantExpr: "^/entities\\('([^/]+)'\\)$",
56+
wantExpr: "^/entities\\('([^/]*)'\\)$",
5757
},
5858
{
5959
name: "OData formatted URL with custom pattern",

parameters/path_parameters_test.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1498,3 +1498,55 @@ paths:
14981498
assert.False(t, valid)
14991499
assert.Len(t, errors, 1)
15001500
}
1501+
1502+
func TestNewValidator_ODataFormattedOpenAPISpecs_Error(t *testing.T) {
1503+
spec := `openapi: 3.0.0
1504+
paths:
1505+
/entities('{Entity'):
1506+
parameters:
1507+
- in: path
1508+
name: Entity
1509+
required: true
1510+
schema:
1511+
type: integer
1512+
get:
1513+
operationId: one
1514+
`
1515+
doc, _ := libopenapi.NewDocument([]byte(spec))
1516+
1517+
m, _ := doc.BuildV3Model()
1518+
1519+
v := NewParameterValidator(&m.Model)
1520+
1521+
request, _ := http.NewRequest(http.MethodGet, "https://things.com/entities('1')", nil)
1522+
1523+
valid, errors := v.ValidatePathParams(request)
1524+
assert.False(t, valid)
1525+
assert.NotEmpty(t, errors)
1526+
}
1527+
1528+
func TestNewValidator_ODataFormattedOpenAPISpecs_ErrorEmptyParameter(t *testing.T) {
1529+
spec := `openapi: 3.0.0
1530+
paths:
1531+
/entities('{Entity}'):
1532+
parameters:
1533+
- in: path
1534+
name: Entity
1535+
required: true
1536+
schema:
1537+
type: integer
1538+
get:
1539+
operationId: one
1540+
`
1541+
doc, _ := libopenapi.NewDocument([]byte(spec))
1542+
1543+
m, _ := doc.BuildV3Model()
1544+
1545+
v := NewParameterValidator(&m.Model)
1546+
1547+
request, _ := http.NewRequest(http.MethodGet, "https://things.com/entities('')", nil)
1548+
1549+
valid, errors := v.ValidatePathParams(request)
1550+
assert.False(t, valid)
1551+
assert.NotEmpty(t, errors)
1552+
}

paths/paths_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,3 +746,26 @@ paths:
746746
assert.NotNil(t, pathItem)
747747
assert.Equal(t, "one", pathItem.Get.OperationId)
748748
}
749+
750+
func TestNewValidator_ODataFormattedOpenAPISpecs_Error(t *testing.T) {
751+
spec := `openapi: 3.0.0
752+
paths:
753+
/entities('{Entity'):
754+
parameters:
755+
- in: path
756+
name: Entity
757+
required: true
758+
schema:
759+
type: integer
760+
get:
761+
operationId: one
762+
`
763+
doc, _ := libopenapi.NewDocument([]byte(spec))
764+
765+
m, _ := doc.BuildV3Model()
766+
767+
request, _ := http.NewRequest(http.MethodGet, "https://things.com/entities('1')", nil)
768+
769+
_, errs, _ := FindPath(request, &m.Model)
770+
assert.NotEmpty(t, errs)
771+
}

0 commit comments

Comments
 (0)