@@ -5,6 +5,8 @@ package cmd
55
66import (
77 "encoding/json"
8+ "net/http"
9+ "net/http/httptest"
810 "os"
911 "path/filepath"
1012 "strings"
@@ -90,11 +92,39 @@ func TestRunLeftRightReport_Success(t *testing.T) {
9092 assert .NotEmpty (t , report .Changes )
9193 assert .NotEmpty (t , report .DateGenerated )
9294 assert .Nil (t , report .Commit )
95+ assert .Equal (t , "../sample-specs/petstorev3-original.json" , report .OriginalPath )
96+ assert .Equal (t , "../sample-specs/petstorev3.json" , report .ModifiedPath )
9397 assert .Contains (t , report .Summary , "paths" )
9498 assert .Equal (t , 30 , report .Summary ["paths" ].Total )
9599 assert .Equal (t , 16 , report .Summary ["paths" ].Breaking )
96100}
97101
102+ func TestRunLeftRightReport_SanitizesURLSourceMetadata (t * testing.T ) {
103+ server := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
104+ if r .URL .Path == "/left.yaml" {
105+ _ , _ = w .Write ([]byte ("openapi: 3.0.3\n info:\n title: Left\n version: '1.0'\n paths: {}\n " ))
106+ return
107+ }
108+ _ , _ = w .Write ([]byte ("openapi: 3.0.3\n info:\n title: Right\n version: '1.1'\n paths:\n /pets:\n get:\n responses:\n \" 200\" :\n description: ok\n " ))
109+ }))
110+ defer server .Close ()
111+
112+ leftURL := server .URL + "/left.yaml?token=left-secret#frag"
113+ rightURL := server .URL + "/right.yaml?token=right-secret#frag"
114+
115+ report , err := runLeftRightReport (leftURL , rightURL , summaryOpts {noColor : true }, nil )
116+
117+ require .NoError (t , err )
118+ require .NotNil (t , report )
119+ assert .Equal (t , server .URL + "/left.yaml" , report .OriginalPath )
120+ assert .Equal (t , server .URL + "/right.yaml" , report .ModifiedPath )
121+
122+ encoded , err := json .Marshal (report )
123+ require .NoError (t , err )
124+ assert .NotContains (t , string (encoded ), "left-secret" )
125+ assert .NotContains (t , string (encoded ), "right-secret" )
126+ }
127+
98128func TestRunLeftRightReport_SummaryIncludesDocumentLevelOpenAPIChanges (t * testing.T ) {
99129 dir := t .TempDir ()
100130
@@ -222,6 +252,8 @@ func TestReportCommand_GitRefUsesLeftRightMode(t *testing.T) {
222252 })
223253
224254 assert .Contains (t , output , `"changes"` )
255+ assert .Contains (t , output , `"originalPath": "HEAD:sample-specs/petstorev3-original.json"` )
256+ assert .Contains (t , output , `"modifiedPath": "sample-specs/petstorev3.json"` )
225257 assert .Contains (t , output , `"summary"` )
226258 assert .NotContains (t , output , `"reports"` )
227259}
0 commit comments