Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion test/e2e/apisix/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

_ "github.com/apache/apisix-ingress-controller/test/e2e/crds"
_ "github.com/apache/apisix-ingress-controller/test/e2e/crds/v1alpha1"
_ "github.com/apache/apisix-ingress-controller/test/e2e/crds/v2"
"github.com/apache/apisix-ingress-controller/test/e2e/framework"
_ "github.com/apache/apisix-ingress-controller/test/e2e/gatewayapi"
_ "github.com/apache/apisix-ingress-controller/test/e2e/ingress"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.

package gatewayapi
package v1alpha1

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.

package gatewayapi
package v1alpha1

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.

package gatewayapi
package v1alpha1

import (
"context"
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/apisix/basic.go → test/e2e/crds/v2/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.

package apisix
package v2

import (
. "github.com/onsi/ginkgo/v2"
Expand Down
105 changes: 89 additions & 16 deletions test/e2e/apisix/consumer.go → test/e2e/crds/v2/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.

package apisix
package v2

import (
"fmt"
Expand Down Expand Up @@ -275,9 +275,6 @@ spec:
`
)

request := func(path string, username, password string) int {
return s.NewAPISIXClient().GET(path).WithBasicAuth(username, password).WithHost("httpbin").Expect().Raw().StatusCode
}
It("Basic tests", func() {
By("apply ApisixRoute")
applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default"}, &apiv2.ApisixRoute{}, defaultApisixRoute)
Expand All @@ -286,19 +283,50 @@ spec:
applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "test-consumer"}, &apiv2.ApisixConsumer{}, basicAuth)

By("verify ApisixRoute with ApisixConsumer")
Eventually(request).WithArguments("/get", "invalid-username", "invalid-password").WithTimeout(5 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusUnauthorized))

Eventually(request).WithArguments("/get", "test-user", "test-password").WithTimeout(5 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusOK))
s.RequestAssert(&scaffold.RequestAssert{
Method: "GET",
Path: "/get",
Host: "httpbin",
BasicAuth: &scaffold.BasicAuth{
Username: "invalid-username",
Password: "invalid-password",
},
Check: scaffold.WithExpectedStatus(http.StatusUnauthorized),
})
s.RequestAssert(&scaffold.RequestAssert{
Method: "GET",
Path: "/get",
Host: "httpbin",
BasicAuth: &scaffold.BasicAuth{
Username: "test-user",
Password: "test-password",
},
Check: scaffold.WithExpectedStatus(http.StatusOK),
})

By("Delete ApisixConsumer")
err := s.DeleteResource("ApisixConsumer", "test-consumer")
Expect(err).ShouldNot(HaveOccurred(), "deleting ApisixConsumer")
Eventually(request).WithArguments("/get", "test-user", "test-password").WithTimeout(5 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusUnauthorized))
s.RequestAssert(&scaffold.RequestAssert{
Method: "GET",
Path: "/get",
Host: "httpbin",
BasicAuth: &scaffold.BasicAuth{
Username: "test-user",
Password: "test-password",
},
Check: scaffold.WithExpectedStatus(http.StatusUnauthorized),
})

By("delete ApisixRoute")
err = s.DeleteResource("ApisixRoute", "default")
Expect(err).ShouldNot(HaveOccurred(), "deleting ApisixRoute")
Eventually(request).WithArguments("/headers", "", "").WithTimeout(5 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusNotFound))
s.RequestAssert(&scaffold.RequestAssert{
Method: "GET",
Path: "/get",
Host: "httpbin",
Check: scaffold.WithExpectedStatus(http.StatusNotFound),
})
})

It("SecretRef tests", func() {
Expand All @@ -313,25 +341,70 @@ spec:
applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "test-consumer"}, &apiv2.ApisixConsumer{}, basicAuthWithSecret)

By("verify ApisixRoute with ApisixConsumer")
Eventually(request).WithArguments("/get", "", "").WithTimeout(5 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusUnauthorized))
Eventually(request).WithArguments("/get", "foo", "bar").WithTimeout(5 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusOK))
s.RequestAssert(&scaffold.RequestAssert{
Method: "GET",
Path: "/get",
Host: "httpbin",
Check: scaffold.WithExpectedStatus(http.StatusUnauthorized),
})
s.RequestAssert(&scaffold.RequestAssert{
Method: "GET",
Path: "/get",
Host: "httpbin",
BasicAuth: &scaffold.BasicAuth{
Username: "foo",
Password: "bar",
},
Check: scaffold.WithExpectedStatus(http.StatusOK),
})

By("update Secret")
err = s.CreateResourceFromString(secretUpdated)
Expect(err).ShouldNot(HaveOccurred(), "updating Secret for ApisixConsumer")

Eventually(request).WithArguments("/get", "foo", "bar").WithTimeout(5 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusUnauthorized))
Eventually(request).WithArguments("/get", "foo-new-user", "bar-new-password").WithTimeout(5 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusOK))
s.RequestAssert(&scaffold.RequestAssert{
Method: "GET",
Path: "/get",
Host: "httpbin",
BasicAuth: &scaffold.BasicAuth{
Username: "foo",
Password: "bar",
},
Check: scaffold.WithExpectedStatus(http.StatusUnauthorized),
})
s.RequestAssert(&scaffold.RequestAssert{
Method: "GET",
Path: "/get",
Host: "httpbin",
BasicAuth: &scaffold.BasicAuth{
Username: "foo-new-user",
Password: "bar-new-password",
},
Check: scaffold.WithExpectedStatus(http.StatusOK),
})

By("Delete ApisixConsumer")
err = s.DeleteResource("ApisixConsumer", "test-consumer")
Expect(err).ShouldNot(HaveOccurred(), "deleting ApisixConsumer")
Eventually(request).WithArguments("/get", "foo-new-user", "bar-new-password").WithTimeout(5 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusUnauthorized))
s.RequestAssert(&scaffold.RequestAssert{
Method: "GET",
Path: "/get",
Host: "httpbin",
BasicAuth: &scaffold.BasicAuth{
Username: "foo-new-user",
Password: "bar-new-password",
},
Check: scaffold.WithExpectedStatus(http.StatusUnauthorized),
})

By("delete ApisixRoute")
err = s.DeleteResource("ApisixRoute", "default")
Expect(err).ShouldNot(HaveOccurred(), "deleting ApisixRoute")
Eventually(request).WithArguments("/get", "", "").WithTimeout(5 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusNotFound))
s.RequestAssert(&scaffold.RequestAssert{
Method: "GET",
Path: "/get",
Host: "httpbin",
Check: scaffold.WithExpectedStatus(http.StatusNotFound),
})
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.

package apisix
package v2

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.

package apisix
package v2

import (
"fmt"
Expand Down
19 changes: 17 additions & 2 deletions test/e2e/apisix/route.go → test/e2e/crds/v2/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.

package apisix
package v2

import (
"context"
Expand Down Expand Up @@ -235,7 +235,22 @@ spec:
match:
paths:
- /*
filter_func: "function(vars)\n local core = require ('apisix.core')\n local body, err = core.request.get_body()\n if not body then\n return false\n end\n\n local data, err = core.json.decode(body)\n if not data then\n return false\n end\n\n if data['foo'] == 'bar' then\n return true\n end\n\n return false\nend"
filter_func: |
function(vars)
local core = require ('apisix.core')
local body, err = core.request.get_body()
if not body then
return false
end
local data, err = core.json.decode(body)
if not data then
return false
end
if data['foo'] == 'bar' then
return true
end
return false
end
backends:
- serviceName: httpbin-service-e2e-test
servicePort: 80
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/apisix/status.go → test/e2e/crds/v2/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.

package apisix
package v2

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/apisix/tls.go → test/e2e/crds/v2/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.

package apisix
package v2

import (
"context"
Expand Down
Loading