Skip to content

Commit 8dca71e

Browse files
committed
address integer typo for auth
1 parent 0c2c89a commit 8dca71e

File tree

3 files changed

+124
-13
lines changed

3 files changed

+124
-13
lines changed

model/auth.go

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -100,18 +100,35 @@ func (a *AuthDefinitions) UnmarshalJSON(b []byte) error {
100100
return fmt.Errorf("no bytes to unmarshal")
101101
}
102102

103-
// See if we can guess based on the first character
104-
switch b[0] {
105-
case '"':
106-
return a.unmarshalFile(b)
107-
case '[':
108-
return a.unmarshalMany(b)
109-
case '{': // single values are not supported, should we support it?
110-
return fmt.Errorf("authDefinitions value '%s' is not supported, it must be an object or string", string(b))
111-
default:
112-
// nil can be returned as both cases are returning errors in case of unmarshal problem.
113-
return nil
103+
for index, char := range b {
104+
105+
switch {
106+
case b[index] >= '0' && b[index] <= '9':
107+
fmt.Print(string(char))
108+
return fmt.Errorf("authDefinitions value '%s' is not supported, it must be an object or string", string(b))
109+
110+
case b[index] == '"':
111+
return a.unmarshalFile(b)
112+
case b[index] == '[':
113+
return a.unmarshalMany(b)
114+
case b[index] == '{': // single values are not supported, should we support it?
115+
return fmt.Errorf("authDefinitions value '%s' is not supported, it must be an object or string", string(b))
116+
}
114117
}
118+
return nil
119+
// See if we can guess based on the first character
120+
// switch b[0] {
121+
// case '"':
122+
// return a.unmarshalFile(b)
123+
// case '[':
124+
// return a.unmarshalMany(b)
125+
// case '{': // single values are not supported, should we support it?
126+
// return fmt.Errorf("authDefinitions value '%s' is not supported, it must be an object or string", string(b))
127+
//
128+
// default:
129+
// // nil can be returned as both cases are returning errors in case of unmarshal problem.
130+
// return nil
131+
// }
115132
}
116133

117134
func (a *AuthDefinitions) unmarshalFile(data []byte) error {

parser/parser_test.go

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,3 +496,98 @@ func TestFromFile(t *testing.T) {
496496
)
497497
}
498498
}
499+
500+
func TestUnmarshalWorkflowBasicTests(t *testing.T) {
501+
t.Run("BasicWorkflowYamlNoAuthDefs", func(t *testing.T) {
502+
workflow, err := FromYAMLSource([]byte(`
503+
id: helloworld
504+
version: '1.0.0'
505+
specVersion: '0.8'
506+
name: Hello World Workflow
507+
description: Inject Hello World
508+
start: Hello State
509+
states:
510+
- name: Hello State
511+
type: inject
512+
data:
513+
result: Hello World!
514+
end: true
515+
`))
516+
assert.Nil(t, err)
517+
assert.NotNil(t, workflow)
518+
})
519+
520+
t.Run("BasicWorkflowBasicAuthJSONSource", func(t *testing.T) {
521+
workflow, err := FromJSONSource([]byte(`
522+
{
523+
"id": "applicantrequest",
524+
"version": "1.0",
525+
"name": "Applicant Request Decision Workflow",
526+
"description": "Determine if applicant request is valid",
527+
"start": "CheckApplication",
528+
"specVersion": "0.7",
529+
"auth": [
530+
{
531+
"name": "testAuth",
532+
"scheme": "bearer",
533+
"properties": {
534+
"token": "test_token"
535+
}
536+
},
537+
{
538+
"name": "testAuth2",
539+
"scheme": "basic",
540+
"properties": {
541+
"username": "test_user",
542+
"password": "test_pwd"
543+
}
544+
}
545+
],
546+
"states": [
547+
{
548+
"name": "Hello State",
549+
"type": "inject",
550+
"data": {
551+
"result": "Hello World!"
552+
},
553+
"end": true
554+
}
555+
]
556+
}
557+
`))
558+
assert.Nil(t, err)
559+
assert.NotNil(t, workflow)
560+
561+
// TODO verify it
562+
// b, _ := json.Marshal(workflow)
563+
// assert.False(t, strings.Contains(string(b), "defs"), "defs should be in the marshalled workflow.")
564+
565+
})
566+
567+
t.Run("BasicWorkflowInteger", func(t *testing.T) {
568+
workflow, err := FromJSONSource([]byte(`
569+
{
570+
"id": "applicantrequest",
571+
"version": "1.0",
572+
"name": "Applicant Request Decision Workflow",
573+
"description": "Determine if applicant request is valid",
574+
"start": "CheckApplication",
575+
"specVersion": "0.7",
576+
"auth": 123,
577+
"states": [
578+
{
579+
"name": "Hello State",
580+
"type": "inject",
581+
"data": {
582+
"result": "Hello World!"
583+
},
584+
"end": true
585+
}
586+
]
587+
}
588+
`))
589+
assert.NotNil(t, err)
590+
assert.Nil(t, workflow)
591+
592+
})
593+
}

parser/testdata/workflows/applicationrequest.multiauth.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121
"password": "test_pwd"
2222
}
2323
}
24-
]
25-
,
24+
],
2625
"functions": [
2726
{
2827
"name": "sendRejectionEmailFunction",

0 commit comments

Comments
 (0)