Skip to content

Commit

Permalink
e2e-test: add e2e tests and CRDs for ApisixConsumer v2 (#1044)
Browse files Browse the repository at this point in the history
  • Loading branch information
lingsamuel authored Jun 1, 2022
1 parent 6c7452f commit e1d496d
Show file tree
Hide file tree
Showing 5 changed files with 951 additions and 752 deletions.
168 changes: 168 additions & 0 deletions samples/deploy/crd/v1/ApisixConsumer.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,174 @@ spec:
preserveUnknownFields: false
versions:
- name: v2beta3
served: true
storage: false
subresources:
status: {}
schema:
openAPIV3Schema:
type: object
properties:
spec:
type: object
required:
- authParameter
properties:
authParameter:
type: object
oneOf:
- required: ["basicAuth"]
- required: ["keyAuth"]
- required: ["wolfRBAC"]
- required: ["jwtAuth"]
- required: ["hmacAuth"]
properties:
basicAuth:
type: object
oneOf:
- required: ["value"]
- required: ["secretRef"]
properties:
value:
type: object
properties:
username:
type: string
minLength: 1
password:
type: string
minLength: 1
required:
- username
- password
secretRef:
type: object
properties:
name:
type: string
minLength: 1
required:
- name
keyAuth:
type: object
oneOf:
- required: ["value"]
- required: ["secretRef"]
properties:
value:
type: object
properties:
key:
type: string
minLength: 1
required:
- key
secretRef:
type: object
properties:
name:
type: string
minLength: 1
required:
- name
jwtAuth:
type: object
oneOf:
- required: ["value"]
- required: ["secretRef"]
properties:
value:
type: object
properties:
key:
type: string
minLength: 1
secret:
type: string
public_key:
type: string
private_key:
type: string
algorithm:
type: string
exp:
type: integer
base64_secret:
type: boolean
required:
- key
secretRef:
type: object
properties:
name:
type: string
minLength: 1
required:
- name
wolfRBAC:
type: object
oneOf:
- required: ["value"]
- required: ["secretRef"]
properties:
value:
type: object
properties:
server:
type: string
appid:
type: string
header_prefix:
type: string
secretRef:
type: object
properties:
name:
type: string
minLength: 1
required:
- name
hmacAuth:
type: object
oneOf:
- required: ["value"]
- required: ["secretRef"]
properties:
value:
type: object
properties:
access_key:
type: string
secret_key:
type: string
algorithm:
type: string
clock_skew:
type: integer
signed_headers:
type: array
items:
type: string
keep_headers:
type: boolean
encode_uri_params:
type: boolean
validate_request_body:
type: boolean
max_req_body:
type: integer
required:
- access_key
- secret_key
secretRef:
type: object
properties:
name:
type: string
minLength: 1
required:
- name
- name: v2
served: true
storage: true
subresources:
Expand Down
55 changes: 50 additions & 5 deletions test/e2e/scaffold/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@
// limitations under the License.
package scaffold

import "fmt"
import (
"errors"
"fmt"
"strings"
)

var (
_apisixConsumerBasicAuth = `
apiVersion: apisix.apache.org/v2beta3
apiVersion: %s
kind: ApisixConsumer
metadata:
name: %s
Expand All @@ -28,9 +32,20 @@ spec:
value:
username: %s
password: %s
`
_apisixConsumerBasicAuthSecret = `
apiVersion: %s
kind: ApisixConsumer
metadata:
name: %s
spec:
authParameter:
basicAuth:
secretRef:
name: %s
`
_apisixConsumerKeyAuth = `
apiVersion: apisix.apache.org/v2beta3
apiVersion: %s
kind: ApisixConsumer
metadata:
name: %s
Expand All @@ -39,15 +54,45 @@ spec:
keyAuth:
value:
key: %s
`
_apisixConsumerKeyAuthSecret = `
apiVersion: %s
kind: ApisixConsumer
metadata:
name: %s
spec:
authParameter:
keyAuth:
secretRef:
name: %s
`
)

func (s *Scaffold) ApisixConsumerBasicAuthCreated(name, username, password string) error {
ac := fmt.Sprintf(_apisixConsumerBasicAuth, name, username, password)
ac := fmt.Sprintf(_apisixConsumerBasicAuth, s.opts.APISIXConsumerVersion, name, username, password)
return s.CreateResourceFromString(ac)
}

func (s *Scaffold) ApisixConsumerBasicAuthSecretCreated(name, secret string) error {
ac := fmt.Sprintf(_apisixConsumerBasicAuthSecret, s.opts.APISIXConsumerVersion, name, secret)
return s.CreateResourceFromString(ac)
}

func (s *Scaffold) ApisixConsumerKeyAuthCreated(name, key string) error {
ac := fmt.Sprintf(_apisixConsumerKeyAuth, name, key)
ac := fmt.Sprintf(_apisixConsumerKeyAuth, s.opts.APISIXConsumerVersion, name, key)
return s.CreateResourceFromString(ac)
}

func (s *Scaffold) ApisixConsumerKeyAuthSecretCreated(name, secret string) error {
ac := fmt.Sprintf(_apisixConsumerKeyAuthSecret, s.opts.APISIXConsumerVersion, name, secret)
return s.CreateResourceFromString(ac)
}

func (s *Scaffold) CreateVersionedApisixConsumer(yml string) error {
if !strings.Contains(yml, "kind: ApisixConsumer") {
return errors.New("not a ApisixConsumer")
}

ac := s.replaceApiVersion(yml, s.opts.APISIXConsumerVersion)
return s.CreateResourceFromString(ac)
}
15 changes: 15 additions & 0 deletions test/e2e/scaffold/scaffold.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"os/exec"
"os/user"
"path/filepath"
"regexp"
"strings"
"text/template"
"time"
Expand All @@ -52,6 +53,7 @@ type Options struct {
HTTPBinServicePort int
APISIXRouteVersion string
APISIXTlsVersion string
APISIXConsumerVersion string
APISIXClusterConfigVersion string
APISIXAdminAPIKey string
EnableWebhooks bool
Expand Down Expand Up @@ -110,6 +112,9 @@ func NewScaffold(o *Options) *Scaffold {
if o.APISIXTlsVersion == "" {
o.APISIXTlsVersion = config.ApisixV2beta3
}
if o.APISIXConsumerVersion == "" {
o.APISIXConsumerVersion = config.ApisixV2beta3
}
if o.APISIXClusterConfigVersion == "" {
o.APISIXClusterConfigVersion = config.ApisixV2beta3
}
Expand Down Expand Up @@ -139,6 +144,7 @@ func NewDefaultScaffold() *Scaffold {
HTTPBinServicePort: 80,
APISIXRouteVersion: kube.ApisixRouteV2beta3,
APISIXTlsVersion: config.ApisixV2beta3,
APISIXConsumerVersion: config.ApisixV2beta3,
APISIXClusterConfigVersion: config.ApisixV2beta3,
EnableWebhooks: false,
APISIXPublishAddress: "",
Expand All @@ -156,6 +162,7 @@ func NewDefaultV2Scaffold() *Scaffold {
HTTPBinServicePort: 80,
APISIXRouteVersion: kube.ApisixRouteV2,
APISIXTlsVersion: config.ApisixV2,
APISIXConsumerVersion: config.ApisixV2,
APISIXClusterConfigVersion: config.ApisixV2,
EnableWebhooks: false,
APISIXPublishAddress: "",
Expand Down Expand Up @@ -491,6 +498,14 @@ func (s *Scaffold) FormatNamespaceLabel(label string) string {
return label
}

var (
versionRegex = regexp.MustCompile(`apiVersion: apisix.apache.org/.*?\n`)
)

func (s *Scaffold) replaceApiVersion(yml, ver string) string {
return versionRegex.ReplaceAllString(yml, "apiVersion: "+ver+"\n")
}

func (s *Scaffold) DisableNamespaceSelector() {
s.opts.disableNamespaceSelector = true
}
Expand Down
Loading

0 comments on commit e1d496d

Please sign in to comment.