@@ -32,6 +32,7 @@ func TestServer(t *testing.T) {
3232 testTemplate bool
3333 testErrCodeXSS bool
3434 testErrDescriptionXSS bool
35+ expected string
3536 }{
3637 {
3738 desc : "Error: Query Values has 'error' key" ,
@@ -77,6 +78,7 @@ func TestServer(t *testing.T) {
7778 statusCode : 200 ,
7879 errorPage : []byte ("test option error page {{.Code}} {{.Err}}" ),
7980 testTemplate : true ,
81+ expected : "test option error page error_code error_description" ,
8082 },
8183 {
8284 desc : "Error: Query Values missing 'state' key, and optional error page, with template having only code" ,
@@ -86,6 +88,7 @@ func TestServer(t *testing.T) {
8688 statusCode : 200 ,
8789 errorPage : []byte ("test option error page {{.Code}}" ),
8890 testTemplate : true ,
91+ expected : "test option error page error_code" ,
8992 },
9093 {
9194 desc : "Error: Query Values missing 'state' key, and optional error page, with template having only error" ,
@@ -95,6 +98,7 @@ func TestServer(t *testing.T) {
9598 statusCode : 200 ,
9699 errorPage : []byte ("test option error page {{.Err}}" ),
97100 testTemplate : true ,
101+ expected : "test option error page error_description" ,
98102 },
99103 {
100104 desc : "Error: Query Values missing 'state' key, and optional error page, having no code or error" ,
@@ -104,6 +108,7 @@ func TestServer(t *testing.T) {
104108 statusCode : 200 ,
105109 errorPage : []byte ("test option error page" ),
106110 testTemplate : true ,
111+ expected : "test option error page" ,
107112 },
108113 {
109114 desc : "Error: Query Values missing 'state' key, using default fail error page" ,
@@ -112,6 +117,7 @@ func TestServer(t *testing.T) {
112117 q : url.Values {"error" : []string {"error_code" }, "error_description" : []string {"error_description" }},
113118 statusCode : 200 ,
114119 testTemplate : true ,
120+ expected : "<p>Error details: error error_code, error description: error_description</p>" ,
115121 },
116122 {
117123 desc : "Error: Query Values missing 'state' key, using default fail error page - Error Code XSS test" ,
@@ -140,6 +146,7 @@ func TestServer(t *testing.T) {
140146 errorPage : []byte ("error: {{.Code}} error_description: {{.Err}}" ),
141147 testTemplate : true ,
142148 testErrCodeXSS : true ,
149+ expected : "<script>alert('this code snippet was executed')</script>" ,
143150 },
144151 {
145152 desc : "Error: Query Values missing 'state' key, using optional fail error page - Error Description XSS test" ,
@@ -150,6 +157,7 @@ func TestServer(t *testing.T) {
150157 errorPage : []byte ("error: {{.Code}} error_description: {{.Err}}" ),
151158 testTemplate : true ,
152159 testErrDescriptionXSS : true ,
160+ expected : "<script>alert('this code snippet was executed')</script>" ,
153161 },
154162 }
155163
@@ -226,14 +234,14 @@ func TestServer(t *testing.T) {
226234
227235 if test .testTemplate {
228236 if test .testErrCodeXSS || test .testErrDescriptionXSS {
229- if ! strings .Contains (string (content ), "<script>alert('this code snippet was executed')</script>" ) {
237+ if ! strings .Contains (string (content ), test . expected ) {
230238 t .Errorf ("TestServer(%s): want escaped html entities" , test .desc )
231239 }
232240 continue
233241 }
234242
235243 if len (test .errorPage ) > 0 && (test .testErrCodeXSS || test .testErrDescriptionXSS ) {
236- if ! strings .Contains (string (content ), "<script>alert('this code snippet was executed')</script>" ) {
244+ if ! strings .Contains (string (content ), test . expected ) {
237245 t .Errorf ("TestServer(%s): want escaped html entities" , test .desc )
238246 }
239247 continue
@@ -244,28 +252,28 @@ func TestServer(t *testing.T) {
244252 errDescription := bytes .Contains (test .errorPage , []byte ("{{.Err}}" ))
245253
246254 if ! errCode && ! errDescription {
247- if ! strings .Contains (string (content ), " test option error page" ) {
255+ if ! strings .Contains (string (content ), test . expected ) {
248256 t .Errorf ("TestServer(%s): -want/+got:\n test option error page" , test .desc )
249257 }
250258 }
251259 if errCode && errDescription {
252- if ! strings .Contains (string (content ), " test option error page error_code error_description" ) {
260+ if ! strings .Contains (string (content ), test . expected ) {
253261 t .Errorf ("TestServer(%s): -want/+got:\n test option error page error_code error_description" , test .desc )
254262 }
255263 }
256264 if errCode && ! errDescription {
257- if ! strings .Contains (string (content ), " test option error page error_code" ) {
265+ if ! strings .Contains (string (content ), test . expected ) {
258266 t .Errorf ("TestServer(%s): -want/+got:\n test option error page error_code" , test .desc )
259267 }
260268 }
261269 if ! errCode && errDescription {
262- if ! strings .Contains (string (content ), " test option error page error_description" ) {
270+ if ! strings .Contains (string (content ), test . expected ) {
263271 t .Errorf ("TestServer(%s): -want/+got:\n test option error page error_description" , test .desc )
264272 }
265273 }
266274 continue
267275 } else {
268- if ! strings .Contains (string (content ), "<p>Error details: error error_code, error description: error_description</p>" ) {
276+ if ! strings .Contains (string (content ), test . expected ) {
269277 t .Errorf ("TestServer(%s): -want/+got:\n test option error page error_code error_description" , test .desc )
270278 }
271279 continue
0 commit comments