Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
8de2206c
Commit
8de2206c
authored
Jan 13, 2016
by
Jacob Vosmaer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Restore missing handleFileUploads
parent
7e5084eb
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
1 deletion
+46
-1
internal/upload/artifacts.go
internal/upload/artifacts.go
+1
-1
main_test.go
main_test.go
+45
-0
No files found.
internal/upload/artifacts.go
View file @
8de2206c
...
@@ -8,6 +8,6 @@ import (
...
@@ -8,6 +8,6 @@ import (
func
Artifacts
(
myAPI
*
api
.
API
,
h
http
.
Handler
)
http
.
Handler
{
func
Artifacts
(
myAPI
*
api
.
API
,
h
http
.
Handler
)
http
.
Handler
{
return
myAPI
.
PreAuthorizeHandler
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
a
*
api
.
Response
)
{
return
myAPI
.
PreAuthorizeHandler
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
a
*
api
.
Response
)
{
r
.
Header
.
Set
(
tempPathHeader
,
a
.
TempPath
)
r
.
Header
.
Set
(
tempPathHeader
,
a
.
TempPath
)
h
.
ServeHTTP
(
w
,
r
)
h
andleFileUploads
(
h
)
.
ServeHTTP
(
w
,
r
)
},
"/authorize"
)
},
"/authorize"
)
}
}
main_test.go
View file @
8de2206c
...
@@ -10,6 +10,7 @@ import (
...
@@ -10,6 +10,7 @@ import (
"io"
"io"
"io/ioutil"
"io/ioutil"
"log"
"log"
"mime/multipart"
"net/http"
"net/http"
"net/http/httptest"
"net/http/httptest"
"os"
"os"
...
@@ -442,6 +443,50 @@ func TestDeniedPublicUploadsFile(t *testing.T) {
...
@@ -442,6 +443,50 @@ func TestDeniedPublicUploadsFile(t *testing.T) {
}
}
}
}
func
TestArtifactsUpload
(
t
*
testing
.
T
)
{
reqBody
:=
&
bytes
.
Buffer
{}
writer
:=
multipart
.
NewWriter
(
reqBody
)
file
,
err
:=
writer
.
CreateFormFile
(
"file"
,
"my.file"
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
fmt
.
Fprint
(
file
,
"SHOULD BE ON DISK, NOT IN MULTIPART"
)
writer
.
Close
()
ts
:=
helper
.
TestServerWithHandler
(
regexp
.
MustCompile
(
`.`
),
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
if
strings
.
HasSuffix
(
r
.
URL
.
Path
,
"/authorize"
)
{
if
_
,
err
:=
fmt
.
Fprintf
(
w
,
`{"TempPath":"%s"}`
,
scratchDir
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
return
}
err
:=
r
.
ParseMultipartForm
(
100000
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
len
(
r
.
MultipartForm
.
Value
)
!=
2
{
// 1 file name, 1 file path
t
.
Error
(
"Expected to receive exactly 2 values"
)
}
if
len
(
r
.
MultipartForm
.
File
)
!=
0
{
t
.
Error
(
"Expected to not receive any files"
)
}
w
.
WriteHeader
(
200
)
})
defer
ts
.
Close
()
ws
:=
startWorkhorseServer
(
ts
.
URL
)
defer
ws
.
Close
()
resource
:=
`/ci/api/v1/builds/123/artifacts`
resp
,
err
:=
http
.
Post
(
ws
.
URL
+
resource
,
writer
.
FormDataContentType
(),
reqBody
)
if
err
!=
nil
{
t
.
Error
(
err
)
}
defer
resp
.
Body
.
Close
()
if
resp
.
StatusCode
!=
200
{
t
.
Errorf
(
"GET %q: expected 200, got %d"
,
resource
,
resp
.
StatusCode
)
}
}
func
setupStaticFile
(
fpath
,
content
string
)
error
{
func
setupStaticFile
(
fpath
,
content
string
)
error
{
cwd
,
err
:=
os
.
Getwd
()
cwd
,
err
:=
os
.
Getwd
()
if
err
!=
nil
{
if
err
!=
nil
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment