Files
libopenapi/datamodel/low/v3/security_scheme_test.go
Dave Shanley d27e66ff3d Refactored SecurityRequirement **breaking change**
The v3 model is wrong and out of sync with the spec. It's been corrected, so the v2 and v2 model for SecurityRequirement have been collapsed down into a base model., they are the same data structures. This has allowed me to delete the complexity of sharing two different models for the same structure, by unifying the model correctly. I am not sure why I decided to change the v3 model, oh well, its been corrected. Long live swagger!
2022-11-18 11:00:34 -05:00

87 lines
2.2 KiB
Go

// Copyright 2022 Princess B33f Heavy Industries / Dave Shanley
// SPDX-License-Identifier: MIT
package v3
import (
"github.com/pb33f/libopenapi/datamodel/low"
"github.com/pb33f/libopenapi/datamodel/low/base"
"github.com/pb33f/libopenapi/index"
"github.com/stretchr/testify/assert"
"gopkg.in/yaml.v3"
"testing"
)
func TestSecurityRequirement_Build(t *testing.T) {
yml := `something:
- read:me
- write:me`
var idxNode yaml.Node
_ = yaml.Unmarshal([]byte(yml), &idxNode)
idx := index.NewSpecIndex(&idxNode)
var n base.SecurityRequirement
err := low.BuildModel(&idxNode, &n)
assert.NoError(t, err)
err = n.Build(idxNode.Content[0], idx)
assert.NoError(t, err)
assert.Len(t, n.Requirements.Value, 1)
assert.Equal(t, "read:me", n.FindRequirement("something")[0].Value)
assert.Equal(t, "write:me", n.FindRequirement("something")[1].Value)
assert.Nil(t, n.FindRequirement("none"))
}
func TestSecurityScheme_Build(t *testing.T) {
yml := `type: tea
description: cake
name: biscuit
in: jar
scheme: lovely
bearerFormat: wow
flows:
implicit:
tokenUrl: https://pb33f.io
openIdConnectUrl: https://pb33f.io/openid
x-milk: please`
var idxNode yaml.Node
_ = yaml.Unmarshal([]byte(yml), &idxNode)
idx := index.NewSpecIndex(&idxNode)
var n SecurityScheme
err := low.BuildModel(&idxNode, &n)
assert.NoError(t, err)
err = n.Build(idxNode.Content[0], idx)
assert.NoError(t, err)
assert.Equal(t, "tea", n.Type.Value)
assert.Equal(t, "cake", n.Description.Value)
assert.Equal(t, "biscuit", n.Name.Value)
assert.Equal(t, "jar", n.In.Value)
assert.Equal(t, "lovely", n.Scheme.Value)
assert.Equal(t, "wow", n.BearerFormat.Value)
assert.Equal(t, "https://pb33f.io/openid", n.OpenIdConnectUrl.Value)
assert.Equal(t, "please", n.FindExtension("x-milk").Value)
assert.Equal(t, "https://pb33f.io", n.Flows.Value.Implicit.Value.TokenUrl.Value)
}
func TestSecurityScheme_Build_Fail(t *testing.T) {
yml := `flows:
$ref: #bork`
var idxNode yaml.Node
_ = yaml.Unmarshal([]byte(yml), &idxNode)
idx := index.NewSpecIndex(&idxNode)
var n SecurityScheme
err := low.BuildModel(&idxNode, &n)
assert.NoError(t, err)
err = n.Build(idxNode.Content[0], idx)
assert.Error(t, err)
}