AlexStocks commented on code in PR #125: URL: https://github.com/apache/dubbo-go-pixiu-samples/pull/125#discussion_r3004220635
########## auth/saml/test/pixiu_test.go: ########## @@ -0,0 +1,142 @@ +/* + * 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 saml + +import ( + "io" + "net/http" + "os" + "path/filepath" + "strings" + "testing" +) + +func sampleFile(rel string) string { + return filepath.Join("..", filepath.FromSlash(rel)) +} + +func TestSampleAssetsExist(t *testing.T) { + assets := []string{ + "pixiu/conf.yaml", + "server/app/server.go", + "docker/docker-compose.yml", + "README.md", + "README_CN.md", + "certs/sp.crt", + "certs/sp.key", + } + + for _, asset := range assets { + if _, err := os.Stat(sampleFile(asset)); err != nil { + t.Fatalf("expected sample asset %s: %v", asset, err) + } + } +} + +func TestPixiuConfigContainsSAMLFilter(t *testing.T) { + data, err := os.ReadFile(sampleFile("pixiu/conf.yaml")) + if err != nil { + t.Fatalf("read pixiu config: %v", err) + } + + content := string(data) + required := []string{ + "dgp.filter.http.auth.saml", + "acs_url:", + "metadata_url:", + "idp_metadata_url:", + "allow_idp_initiated: true", + "forward_attributes:", + "X-User-Email", + "X-User-Name", + "/app", + } + + for _, token := range required { + if !strings.Contains(content, token) { + t.Fatalf("expected pixiu config to contain %q", token) + } + } +} + +func TestMetadataEndpoint(t *testing.T) { + gatewayURL := requireSAMLIntegration(t) + + client := newSAMLTestHTTPClient() + req, err := http.NewRequest(http.MethodGet, gatewayURL+"/saml/metadata", nil) + if err != nil { Review Comment: [P2] 硬编码超时 5s,建议提取为常量 defaultTestTimeout。 ########## auth/saml/test/integration_helpers_test.go: ########## @@ -0,0 +1,144 @@ +/* + * 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 saml + +import ( + "net/http" + "os" + "strings" + "testing" + "time" +) + +const ( + defaultSAMLGatewayURL = "http://127.0.0.1:8888" + samlGatewayURLEnv = "SAML_GATEWAY_URL" + samlIntegrationTestsEnv = "RUN_SAML_INTEGRATION_TESTS" + samlTestTimeout = 5 * time.Second +) + Review Comment: [P2] 全局变量 samlTestHTTPClient 在并发测试时可能有问题,建议每个测试创建独立 client。 -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
