@ -29,7 +29,7 @@ func generateImg() bytes.Buffer {
return buff
}
func createAttachment ( t * testing . T , session * TestSession , repoURL , filename string , buff bytes . Buffer , expectedStatus int ) string {
func createAttachment ( t * testing . T , session * TestSession , csrf , repoURL , filename string , buff bytes . Buffer , expectedStatus int ) string {
body := & bytes . Buffer { }
// Setup multi-part
@ -41,8 +41,6 @@ func createAttachment(t *testing.T, session *TestSession, repoURL, filename stri
err = writer . Close ( )
assert . NoError ( t , err )
csrf := GetCSRF ( t , session , repoURL )
req := NewRequestWithBody ( t , "POST" , repoURL + "/issues/attachments" , body )
req . Header . Add ( "X-Csrf-Token" , csrf )
req . Header . Add ( "Content-Type" , writer . FormDataContentType ( ) )
@ -59,15 +57,14 @@ func createAttachment(t *testing.T, session *TestSession, repoURL, filename stri
func TestCreateAnonymousAttachment ( t * testing . T ) {
defer tests . PrepareTestEnv ( t ) ( )
session := emptyTestSession ( t )
// this test is not right because it just doesn't pass the CSRF validation
createAttachment ( t , session , "user2/repo1" , "image.png" , generateImg ( ) , http . StatusBadRequest )
createAttachment ( t , session , GetCSRF ( t , session , "/user/login" ) , "user2/repo1" , "image.png" , generateImg ( ) , http . StatusSeeOther )
}
func TestCreateIssueAttachment ( t * testing . T ) {
defer tests . PrepareTestEnv ( t ) ( )
const repoURL = "user2/repo1"
session := loginUser ( t , "user2" )
uuid := createAttachment ( t , session , repoURL , "image.png" , generateImg ( ) , http . StatusOK )
uuid := createAttachment ( t , session , GetCSRF ( t , session , repoURL ) , repoURL , "image.png" , generateImg ( ) , http . StatusOK )
req := NewRequest ( t , "GET" , repoURL + "/issues/new" )
resp := session . MakeRequest ( t , req , http . StatusOK )