schema_test.go 4.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. package schema_test
  18. import (
  19. "net/http"
  20. . "github.com/onsi/ginkgo/v2"
  21. "github.com/apisix/manager-api/test/e2e/base"
  22. )
  23. var _ = Describe("Schema Test", func() {
  24. DescribeTable("test schema basic",
  25. func(testCase base.HttpTestCase) {
  26. base.RunTestCase(testCase)
  27. },
  28. Entry("get consumer schema of plugin", base.HttpTestCase{
  29. Object: base.ManagerApiExpect(),
  30. Method: http.MethodGet,
  31. Path: "/apisix/admin/schema/plugins/jwt-auth",
  32. Query: "schema_type=consumer",
  33. Headers: map[string]string{"Authorization": base.GetToken()},
  34. ExpectStatus: http.StatusOK,
  35. ExpectBody: `{"dependencies":{"algorithm":{"oneOf":[{"properties":{"algorithm":{"default":"HS256","enum":["HS256","HS512"]}}},{"properties":{"algorithm":{"enum":["ES256","RS256"]},"private_key":{"type":"string"},"public_key":{"type":"string"}},"required":["private_key","public_key"]},{"properties":{"algorithm":{"enum":["ES256","RS256"]},"vault":{"properties":{},"type":"object"}},"required":["vault"]}]}},"properties":{"algorithm":{"default":"HS256","enum":["ES256","HS256","HS512","RS256"],"type":"string"},"base64_secret":{"default":false,"type":"boolean"},"exp":{"default":86400,"minimum":1,"type":"integer"},"key":{"type":"string"},"lifetime_grace_period":{"default":0,"minimum":0,"type":"integer"},"secret":{"type":"string"},"vault":{"properties":{},"type":"object"}},"required":["key"],"type":"object"}`,
  36. Sleep: base.SleepTime,
  37. }),
  38. Entry("get route schema of plugin", base.HttpTestCase{
  39. Object: base.ManagerApiExpect(),
  40. Method: http.MethodGet,
  41. Path: "/apisix/admin/schema/plugins/jwt-auth",
  42. Headers: map[string]string{"Authorization": base.GetToken()},
  43. ExpectStatus: http.StatusOK,
  44. ExpectBody: `{"$comment":"this is a mark for our injected plugin schema","properties":{"_meta":{"properties":{"disable":{"type":"boolean"},"error_response":{"oneOf":[{"type":"string"},{"type":"object"}]},"filter":{"description":"filter determines whether the plugin needs to be executed at runtime","type":"array"},"priority":{"description":"priority of plugins by customized order","type":"integer"}},"type":"object"},"cookie":{"default":"jwt","type":"string"},"header":{"default":"authorization","type":"string"},"query":{"default":"jwt","type":"string"}},"type":"object"}`,
  45. Sleep: base.SleepTime,
  46. }),
  47. Entry("get schema of non-existent plugin", base.HttpTestCase{
  48. Object: base.ManagerApiExpect(),
  49. Method: http.MethodGet,
  50. Path: "/apisix/admin/schema/plugins/non-existent",
  51. Headers: map[string]string{"Authorization": base.GetToken()},
  52. ExpectStatus: http.StatusNotFound,
  53. ExpectBody: `schema of plugins non-existent not found`,
  54. Sleep: base.SleepTime,
  55. }),
  56. Entry("get schema of consumer", base.HttpTestCase{
  57. Object: base.ManagerApiExpect(),
  58. Method: http.MethodGet,
  59. Path: "/apisix/admin/schemas/consumer",
  60. Headers: map[string]string{"Authorization": base.GetToken()},
  61. ExpectStatus: http.StatusOK,
  62. ExpectBody: `{"properties":{"create_time":{"type":"integer"},"desc":{"maxLength":256,"type":"string"},"group_id":{"anyOf":[{"maxLength":64,"minLength":1,"pattern":"^[a-zA-Z0-9-_.]+$","type":"string"},{"minimum":1,"type":"integer"}]},"labels":{"description":"key/value pairs to specify attributes","patternProperties":{".*":{"description":"value of label","maxLength":64,"minLength":1,"pattern":"^\\S+$","type":"string"}},"type":"object"},"plugins":{"type":"object"},"update_time":{"type":"integer"},"username":{"maxLength":100,"minLength":1,"pattern":"^[a-zA-Z0-9_]+$","type":"string"}},"required":["username"],"type":"object"}`,
  63. Sleep: base.SleepTime,
  64. }),
  65. Entry("get schema of non-existent resources", base.HttpTestCase{
  66. Object: base.ManagerApiExpect(),
  67. Method: http.MethodGet,
  68. Path: "/apisix/admin/schemas/non-existent",
  69. Headers: map[string]string{"Authorization": base.GetToken()},
  70. ExpectStatus: http.StatusNotFound,
  71. ExpectBody: `schema of non-existent not found`,
  72. Sleep: base.SleepTime,
  73. }),
  74. )
  75. })