@@ -779,8 +779,8 @@ func TestPipelineCheckPeriodicSchedules(t *testing.T) {
779
779
})
780
780
}
781
781
782
- func TestPipelineNameAvailable (t * testing.T ) {
783
- tmp , _ := ioutil .TempDir ("" , "TestPipelineNameAvailable " )
782
+ func TestPipelineNameValidation (t * testing.T ) {
783
+ tmp , _ := ioutil .TempDir ("" , "TestPipelineNameValidation " )
784
784
dataDir := tmp
785
785
786
786
gaia .Cfg = & gaia.Config {
@@ -870,6 +870,31 @@ func TestPipelineNameAvailable(t *testing.T) {
870
870
}
871
871
})
872
872
873
+ t .Run ("fails for pipeline name with invalid character" , func (t * testing.T ) {
874
+ req := httptest .NewRequest (echo .GET , "/" , nil )
875
+ req .Header .Set ("Content-Type" , "application/json" )
876
+ rec := httptest .NewRecorder ()
877
+ c := e .NewContext (req , rec )
878
+ c .SetPath ("/api/" + gaia .APIVersion + "/pipeline/name" )
879
+ q := req .URL .Query ()
880
+ q .Add ("name" , "this[]isinvalid;" )
881
+ req .URL .RawQuery = q .Encode ()
882
+
883
+ _ = PipelineNameAvailable (c )
884
+
885
+ if rec .Code != http .StatusBadRequest {
886
+ t .Fatalf ("expected response code %v got %v" , http .StatusBadRequest , rec .Code )
887
+ }
888
+ bodyBytes , err := ioutil .ReadAll (rec .Body )
889
+ if err != nil {
890
+ t .Fatalf ("cannot read response body: %s" , err .Error ())
891
+ }
892
+ nameContainsInvalidCharacter := "must match [A-z][0-9][-][_][ ]"
893
+ if string (bodyBytes [:]) != nameContainsInvalidCharacter {
894
+ t .Fatalf ("error message should be '%s' but was '%s'" , nameContainsInvalidCharacter , string (bodyBytes [:]))
895
+ }
896
+ })
897
+
873
898
t .Run ("works for pipeline with different name" , func (t * testing.T ) {
874
899
req := httptest .NewRequest (echo .GET , "/" , nil )
875
900
req .Header .Set ("Content-Type" , "application/json" )
0 commit comments