Skip to content

Commit 5e03b03

Browse files
authored
ci: add missing commands and tools for kafka, pulsar and storage integration tests (pingcap#1163)
close pingcap#1162
1 parent 73899c3 commit 5e03b03

File tree

4 files changed

+284
-6
lines changed

4 files changed

+284
-6
lines changed

Makefile

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@ storage_consumer:
141141
pulsar_consumer:
142142
$(GOBUILD) -ldflags '$(LDFLAGS)' -o bin/cdc_pulsar_consumer ./cmd/pulsar-consumer/main.go
143143

144+
oauth2_server:
145+
$(GOBUILD) -ldflags '$(LDFLAGS)' -o bin/oauth2-server ./cmd/oauth2-server/main.go
146+
144147
filter_helper:
145148
$(GOBUILD) -ldflags '$(LDFLAGS)' -o bin/cdc_filter_helper ./cmd/filter-helper/main.go
146149

@@ -171,7 +174,7 @@ check_third_party_binary:
171174
@which bin/minio
172175
@which bin/bin/schema-registry-start
173176

174-
integration_test_build: check_failpoint_ctl
177+
integration_test_build: check_failpoint_ctl storage_consumer kafka_consumer pulsar_consumer oauth2_server
175178
$(FAILPOINT_ENABLE)
176179
$(GOTEST) -ldflags '$(LDFLAGS)' -c -cover -covermode=atomic \
177180
-coverpkg=github.com/pingcap/ticdc/... \
@@ -191,16 +194,16 @@ check_failpoint_ctl: tools/bin/failpoint-ctl
191194

192195
integration_test: integration_test_mysql
193196

194-
integration_test_mysql:
195-
tests/integration_tests/run.sh mysql "$(CASE)" "$(NEWARCH)" "$(START_AT)"
197+
integration_test_mysql: check_third_party_binary
198+
tests/integration_tests/run.sh mysql "$(CASE)" "$(START_AT)"
196199

197200
integration_test_kafka: check_third_party_binary
198201
tests/integration_tests/run.sh kafka "$(CASE)" "$(START_AT)"
199202

200-
integration_test_storage:
203+
integration_test_storage: check_third_party_binary
201204
tests/integration_tests/run.sh storage "$(CASE)" "$(START_AT)"
202205

203-
integration_test_pulsar:
206+
integration_test_pulsar: check_third_party_binary
204207
tests/integration_tests/run.sh pulsar "$(CASE)" "$(START_AT)"
205208

206209
unit_test: check_failpoint_ctl generate-protobuf

cmd/oauth2-server/main.go

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
// Copyright 2024 PingCAP, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
package main
15+
16+
import (
17+
"fmt"
18+
"net/http"
19+
20+
"github.com/go-oauth2/oauth2/v4/errors"
21+
"github.com/go-oauth2/oauth2/v4/generates"
22+
"github.com/go-oauth2/oauth2/v4/manage"
23+
"github.com/go-oauth2/oauth2/v4/models"
24+
"github.com/go-oauth2/oauth2/v4/server"
25+
"github.com/go-oauth2/oauth2/v4/store"
26+
"github.com/golang-jwt/jwt"
27+
"github.com/pingcap/log"
28+
"github.com/spf13/cobra"
29+
"go.uber.org/zap"
30+
)
31+
32+
const openIDConfiguration = `
33+
{
34+
"issuer": "http://localhost:%d/",
35+
"authorization_endpoint": "http://localhost:%d/authorize",
36+
"token_endpoint": "http://localhost:%d/token",
37+
"scopes_supported": [
38+
"openid",
39+
"profile"
40+
],
41+
"response_types_supported": [
42+
"code",
43+
"token",
44+
"id_token",
45+
"code token",
46+
"code id_token",
47+
"token id_token",
48+
"code token id_token"
49+
],
50+
"code_challenge_methods_supported": [
51+
"HS256",
52+
"plain"
53+
],
54+
"response_modes_supported": [
55+
"query",
56+
"fragment",
57+
"form_post"
58+
],
59+
"subject_types_supported": [
60+
"public"
61+
],
62+
"id_token_signing_alg_values_supported": [
63+
"HS256"
64+
],
65+
"token_endpoint_auth_methods_supported": [
66+
"client_secret_basic",
67+
"client_secret_post",
68+
"private_key_jwt"
69+
],
70+
"claims_supported": [
71+
"aud",
72+
"created_at",
73+
"email",
74+
"email_verified",
75+
"exp",
76+
"iat",
77+
"identities",
78+
"iss",
79+
"name"
80+
],
81+
"request_uri_parameter_supported": false,
82+
"request_parameter_supported": false
83+
}
84+
`
85+
86+
type oauth2ServerConfig struct {
87+
tokenSignSecret string
88+
clientID string
89+
clientSecret string
90+
port int
91+
}
92+
93+
var serverConfig = newServerConfig()
94+
95+
func newServerConfig() *oauth2ServerConfig {
96+
return &oauth2ServerConfig{}
97+
}
98+
99+
func main() {
100+
cmd := &cobra.Command{
101+
Use: "oauth2 server",
102+
Run: run,
103+
}
104+
// Flags for the root command
105+
cmd.Flags().StringVar(&serverConfig.tokenSignSecret, "token-secret",
106+
"SJhX36_KapYSybBtJq35lxX_Brr4LRURSkm7QmXJGmy8pUFW9EIOcVQPsykz9-jj", "Secret to sign token")
107+
cmd.Flags().StringVar(&serverConfig.clientID, "client-id", "1234", "Client ID of oauth2")
108+
cmd.Flags().StringVar(&serverConfig.clientSecret, "client-secret", "e0KVlA2EiBfjoN13olyZd2kv1KL", "Client secret of oauth2")
109+
cmd.Flags().IntVar(&serverConfig.port, "log-file", 9096, "log file path")
110+
if err := cmd.Execute(); err != nil {
111+
fmt.Println(err)
112+
}
113+
}
114+
115+
func run(_ *cobra.Command, _ []string) {
116+
manager := manage.NewDefaultManager()
117+
// token memory store
118+
manager.MustTokenStorage(store.NewMemoryTokenStore())
119+
manager.MapAccessGenerate(generates.NewJWTAccessGenerate("", []byte(serverConfig.tokenSignSecret), jwt.SigningMethodHS512))
120+
121+
// client memory store
122+
clientStore := store.NewClientStore()
123+
err := clientStore.Set(serverConfig.clientID, &models.Client{
124+
ID: serverConfig.clientID,
125+
Secret: serverConfig.clientSecret,
126+
Domain: fmt.Sprintf("http://localhost:%d", serverConfig.port),
127+
})
128+
if err != nil {
129+
log.Panic("set client failed", zap.Error(err))
130+
}
131+
manager.MapClientStorage(clientStore)
132+
133+
srv := server.NewDefaultServer(manager)
134+
srv.SetAllowGetAccessRequest(true)
135+
srv.SetClientInfoHandler(server.ClientFormHandler)
136+
srv.SetInternalErrorHandler(func(err error) (re *errors.Response) {
137+
log.Error("Internal Error:", zap.Error(err))
138+
return
139+
})
140+
srv.SetResponseErrorHandler(func(re *errors.Response) {
141+
log.Error("Response Error:", zap.Error(re.Error))
142+
})
143+
http.Handle("/authorize", logMiddleware(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
144+
err := srv.HandleAuthorizeRequest(w, r)
145+
if err != nil {
146+
http.Error(w, err.Error(), http.StatusBadRequest)
147+
}
148+
})))
149+
http.Handle("/token", logMiddleware(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
150+
if err := srv.HandleTokenRequest(w, r); err != nil {
151+
http.Error(w, err.Error(), http.StatusInternalServerError)
152+
}
153+
})))
154+
http.Handle("/.well-known/openid-configuration", logMiddleware(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
155+
_, _ = w.Write([]byte(fmt.Sprintf(openIDConfiguration, serverConfig.port, serverConfig.port, serverConfig.port)))
156+
w.WriteHeader(200)
157+
})))
158+
log.Info("starting auth2 server", zap.Int("port", serverConfig.port))
159+
log.Panic("run auth2 server failed", zap.Error(http.ListenAndServe(fmt.Sprintf(":%d", serverConfig.port), nil)))
160+
}
161+
162+
func logMiddleware(next http.Handler) http.Handler {
163+
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
164+
next.ServeHTTP(w, r)
165+
log.Info("oauth server api is called", zap.String("path", r.URL.Path))
166+
})
167+
}

go.mod

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@ require (
2525
github.com/dustin/go-humanize v1.0.1
2626
github.com/fatih/color v1.18.0
2727
github.com/gin-gonic/gin v1.9.1
28+
github.com/go-oauth2/oauth2/v4 v4.5.2
2829
github.com/go-sql-driver/mysql v1.7.1
2930
github.com/goccy/go-json v0.10.2
3031
github.com/gogo/protobuf v1.3.2
32+
github.com/golang-jwt/jwt v3.2.2+incompatible
3133
github.com/golang/mock v1.6.0
3234
github.com/google/btree v1.1.2
3335
github.com/google/uuid v1.6.0
@@ -178,7 +180,6 @@ require (
178180
github.com/goccy/go-reflect v1.2.0 // indirect
179181
github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect
180182
github.com/godbus/dbus/v5 v5.0.4 // indirect
181-
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
182183
github.com/golang-jwt/jwt/v4 v4.5.1 // indirect
183184
github.com/golang-jwt/jwt/v5 v5.2.1 // indirect
184185
github.com/golang/glog v1.2.1 // indirect
@@ -294,6 +295,13 @@ require (
294295
github.com/tiancaiamao/appdash v0.0.0-20181126055449-889f96f722a2 // indirect
295296
github.com/tiancaiamao/gp v0.0.0-20221230034425-4025bc8a4d4a // indirect
296297
github.com/tidwall/btree v1.7.0 // indirect
298+
github.com/tidwall/buntdb v1.3.0 // indirect
299+
github.com/tidwall/gjson v1.14.3 // indirect
300+
github.com/tidwall/grect v0.1.4 // indirect
301+
github.com/tidwall/match v1.1.1 // indirect
302+
github.com/tidwall/pretty v1.2.0 // indirect
303+
github.com/tidwall/rtred v0.1.2 // indirect
304+
github.com/tidwall/tinyqueue v0.1.1 // indirect
297305
github.com/tklauser/go-sysconf v0.3.12 // indirect
298306
github.com/tklauser/numcpus v0.6.1 // indirect
299307
github.com/tmc/grpc-websocket-proxy v0.0.0-20220101234140-673ab2c3ae75 // indirect

0 commit comments

Comments
 (0)