@@ -92,9 +92,9 @@ func signJWTWithStandardClaims(t *testing.T, privKey string, claims interface{})
92
92
// TestAutoConfigInitialConfiguration is really an integration test of all the moving parts of the AutoConfig.InitialConfiguration RPC.
93
93
// Full testing of the individual parts will not be done in this test:
94
94
//
95
- // * Any implementations of the AutoConfigAuthorizer interface (although these test do use the jwtAuthorizer)
96
- // * Each of the individual config generation functions. These can be unit tested separately and should NOT
97
- // require running test servers
95
+ // - Any implementations of the AutoConfigAuthorizer interface (although these test do use the jwtAuthorizer)
96
+ // - Each of the individual config generation functions. These can be unit tested separately and should NOT
97
+ // require running test servers
98
98
func TestAutoConfigInitialConfiguration (t * testing.T ) {
99
99
if testing .Short () {
100
100
t .Skip ("too slow for testing.Short" )
@@ -236,6 +236,29 @@ func TestAutoConfigInitialConfiguration(t *testing.T) {
236
236
},
237
237
err : "Permission denied: Failed JWT authorization: no known key successfully validated the token signature" ,
238
238
},
239
+ "bad-req-node" : {
240
+ request : & pbautoconf.AutoConfigRequest {
241
+ Node : "bad node" ,
242
+ JWT : signJWTWithStandardClaims (t , priv , map [string ]interface {}{"consul_node_name" : "test-node" }),
243
+ },
244
+ err : "Invalid request field. node =" ,
245
+ },
246
+ "bad-req-segment" : {
247
+ request : & pbautoconf.AutoConfigRequest {
248
+ Node : "test-node" ,
249
+ Segment : "bad segment" ,
250
+ JWT : signJWTWithStandardClaims (t , priv , map [string ]interface {}{"consul_node_name" : "test-node" }),
251
+ },
252
+ err : "Invalid request field. segment =" ,
253
+ },
254
+ "bad-req-partition" : {
255
+ request : & pbautoconf.AutoConfigRequest {
256
+ Node : "test-node" ,
257
+ Partition : "bad partition" ,
258
+ JWT : signJWTWithStandardClaims (t , priv , map [string ]interface {}{"consul_node_name" : "test-node" }),
259
+ },
260
+ err : "Invalid request field. partition =" ,
261
+ },
239
262
"claim-assertion-failed" : {
240
263
request : & pbautoconf.AutoConfigRequest {
241
264
Node : "test-node" ,
@@ -850,3 +873,39 @@ func TestAutoConfig_updateJoinAddressesInConfig(t *testing.T) {
850
873
851
874
backend .AssertExpectations (t )
852
875
}
876
+
877
+ func TestAutoConfig_invalidSegmentName (t * testing.T ) {
878
+ invalid := []string {
879
+ "\n " ,
880
+ "\r " ,
881
+ "\t " ,
882
+ "`" ,
883
+ `'` ,
884
+ `"` ,
885
+ ` ` ,
886
+ `a b` ,
887
+ `a'b` ,
888
+ `a or b` ,
889
+ `a and b` ,
890
+ `segment name` ,
891
+ `segment"name` ,
892
+ `"segment"name` ,
893
+ `"segment" name` ,
894
+ `segment'name'` ,
895
+ }
896
+ valid := []string {
897
+ `` ,
898
+ `a` ,
899
+ `a.b` ,
900
+ `a.b.c` ,
901
+ `a-b-c` ,
902
+ `segment.name` ,
903
+ }
904
+
905
+ for _ , s := range invalid {
906
+ require .True (t , invalidSegmentName .MatchString (s ), "incorrect match: %v" , s )
907
+ }
908
+ for _ , s := range valid {
909
+ require .False (t , invalidSegmentName .MatchString (s ), "incorrect match: %v" , s )
910
+ }
911
+ }
0 commit comments