starsz commented on code in PR #2608: URL: https://github.com/apache/apisix-dashboard/pull/2608#discussion_r970263917
########## api/test/e2e/oidc/oidc_test.go: ########## @@ -0,0 +1,75 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package oidc_test + +import ( + "fmt" + "net/http" + + "github.com/onsi/ginkgo" + "github.com/onsi/ginkgo/extensions/table" + + "github.com/apisix/manager-api/test/e2e/base" +) + +var _ = ginkgo.Describe("Oidc", func() { + + table.DescribeTable("test oidc module", + func(tc base.HttpTestCase) { + base.RunTestCase(tc) + }, + + // apisix/admin/oidc/login + table.Entry("Access the oidc/login", base.HttpTestCase{ + Object: base.ManagerApiExpect(), + Method: http.MethodGet, + Path: "/apisix/admin/oidc/login", + ExpectStatus: http.StatusOK, + }), + + // apisix/admin/oidc/callback + table.Entry("Access with invalid state", base.HttpTestCase{ + Object: base.ManagerApiExpect(), + Method: http.MethodGet, + Path: "/apisix/admin/oidc/callback", + Query: fmt.Sprintf("code=%s&state=%s", base.OidcCode, "invalid_state"), + ExpectStatus: http.StatusForbidden, + }), + table.Entry("Access with invalid authentication code, failed to fetch token", base.HttpTestCase{ + Object: base.ManagerApiExpect(), + Method: http.MethodGet, + Path: "/apisix/admin/oidc/callback", + Query: fmt.Sprintf("code=%s&state=%s", "invalid_code", base.OidcState), + ExpectStatus: http.StatusForbidden, + }), + table.Entry("Access with valid authentication code, succeed to fetch user's id", base.HttpTestCase{ + Object: base.ManagerApiExpect(), + Method: http.MethodGet, + Path: "/apisix/admin/oidc/callback", + Query: fmt.Sprintf("code=%s&state=%s", base.OidcCode, base.OidcState), Review Comment: What's the value of `OidcCode` ? ########## api/test/e2e/oidc/oidc_test.go: ########## @@ -0,0 +1,75 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package oidc_test + +import ( + "fmt" + "net/http" + + "github.com/onsi/ginkgo" + "github.com/onsi/ginkgo/extensions/table" + + "github.com/apisix/manager-api/test/e2e/base" +) + +var _ = ginkgo.Describe("Oidc", func() { + + table.DescribeTable("test oidc module", + func(tc base.HttpTestCase) { + base.RunTestCase(tc) + }, + + // apisix/admin/oidc/login + table.Entry("Access the oidc/login", base.HttpTestCase{ + Object: base.ManagerApiExpect(), + Method: http.MethodGet, + Path: "/apisix/admin/oidc/login", + ExpectStatus: http.StatusOK, + }), + + // apisix/admin/oidc/callback + table.Entry("Access with invalid state", base.HttpTestCase{ + Object: base.ManagerApiExpect(), + Method: http.MethodGet, + Path: "/apisix/admin/oidc/callback", + Query: fmt.Sprintf("code=%s&state=%s", base.OidcCode, "invalid_state"), + ExpectStatus: http.StatusForbidden, + }), + table.Entry("Access with invalid authentication code, failed to fetch token", base.HttpTestCase{ + Object: base.ManagerApiExpect(), + Method: http.MethodGet, + Path: "/apisix/admin/oidc/callback", + Query: fmt.Sprintf("code=%s&state=%s", "invalid_code", base.OidcState), + ExpectStatus: http.StatusForbidden, + }), + table.Entry("Access with valid authentication code, succeed to fetch user's id", base.HttpTestCase{ + Object: base.ManagerApiExpect(), + Method: http.MethodGet, + Path: "/apisix/admin/oidc/callback", + Query: fmt.Sprintf("code=%s&state=%s", base.OidcCode, base.OidcState), + ExpectStatus: http.StatusOK, + }), + + // apisix/admin/oidc/logout + table.Entry("oidc logout", base.HttpTestCase{ + Object: base.ManagerApiExpect(), + Method: http.MethodGet, + Path: "/apisix/admin/oidc/logout", + ExpectStatus: http.StatusOK, + }), Review Comment: We should request after the logout and test it return 302. ########## api/test/e2e/oidc/oidc_test.go: ########## @@ -0,0 +1,75 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package oidc_test + +import ( + "fmt" + "net/http" + + "github.com/onsi/ginkgo" + "github.com/onsi/ginkgo/extensions/table" + + "github.com/apisix/manager-api/test/e2e/base" +) + +var _ = ginkgo.Describe("Oidc", func() { + + table.DescribeTable("test oidc module", + func(tc base.HttpTestCase) { + base.RunTestCase(tc) + }, + + // apisix/admin/oidc/login + table.Entry("Access the oidc/login", base.HttpTestCase{ + Object: base.ManagerApiExpect(), + Method: http.MethodGet, + Path: "/apisix/admin/oidc/login", + ExpectStatus: http.StatusOK, Review Comment: And I think you should save the cookie, and request with the cookie in the later request. ########## api/test/e2e/oidc/oidc_test.go: ########## @@ -0,0 +1,75 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package oidc_test + +import ( + "fmt" + "net/http" + + "github.com/onsi/ginkgo" + "github.com/onsi/ginkgo/extensions/table" + + "github.com/apisix/manager-api/test/e2e/base" +) + +var _ = ginkgo.Describe("Oidc", func() { + + table.DescribeTable("test oidc module", + func(tc base.HttpTestCase) { + base.RunTestCase(tc) + }, + + // apisix/admin/oidc/login + table.Entry("Access the oidc/login", base.HttpTestCase{ + Object: base.ManagerApiExpect(), + Method: http.MethodGet, + Path: "/apisix/admin/oidc/login", + ExpectStatus: http.StatusOK, Review Comment: Why the status is `http.StatusOK `? I guess it should be 302. ########## api/internal/filter/authentication_test.go: ########## @@ -71,4 +82,12 @@ func TestAuthenticationMiddleware_Handle(t *testing.T) { validToken := genToken("admin", time.Now().Unix(), time.Now().Unix()+60*3600) w = performRequest(r, "GET", "/apisix/admin/routes", map[string]string{"Authorization": validToken}) assert.Equal(t, http.StatusOK, w.Code) + + // test oidc auth with wrong cookie + w = performOidcRequest(r, "GET", "/apisix/admin/routes", "xxx") + assert.Equal(t, http.StatusUnauthorized, w.Code) + + // test oidc auth success + w = performOidcRequest(r, "GET", "/apisix/admin/routes", conf.OidcId) + assert.Equal(t, http.StatusUnauthorized, w.Code) Review Comment: What's the reason that the oidc auth success but the code is `http.StatusUnauthorized`? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
