mirror of
https://github.com/clearlinux/docker.git
synced 2026-10-04 07:48:44 +00:00
Add an API test for docker build -f Dockerfile
I noticed that while we have tests to make sure that people don't specify a Dockerfile (via -f) that's outside of the build context when using the docker cli, we don't check on the server side to make sure that API users have the same check done. This would be a security risk. While in there I had to add a new util func for the tests to allow us to send content to the server that isn't json encoded - in this case a tarball Signed-off-by: Doug Davis <dug@us.ibm.com>
This commit is contained in:
committed by
Arnaud Porterie
parent
01b46c21aa
commit
198ff76de5
@@ -274,6 +274,15 @@ func daemonHost() string {
|
||||
}
|
||||
|
||||
func sockRequest(method, endpoint string, data interface{}) ([]byte, error) {
|
||||
jsonData := bytes.NewBuffer(nil)
|
||||
if err := json.NewEncoder(jsonData).Encode(data); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return sockRequestRaw(method, endpoint, jsonData, "application/json")
|
||||
}
|
||||
|
||||
func sockRequestRaw(method, endpoint string, data io.Reader, ct string) ([]byte, error) {
|
||||
daemon := daemonHost()
|
||||
daemonUrl, err := url.Parse(daemon)
|
||||
if err != nil {
|
||||
@@ -296,17 +305,16 @@ func sockRequest(method, endpoint string, data interface{}) ([]byte, error) {
|
||||
client := httputil.NewClientConn(c, nil)
|
||||
defer client.Close()
|
||||
|
||||
jsonData := bytes.NewBuffer(nil)
|
||||
if err := json.NewEncoder(jsonData).Encode(data); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
req, err := http.NewRequest(method, endpoint, jsonData)
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
req, err := http.NewRequest(method, endpoint, data)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not create new request: %v", err)
|
||||
}
|
||||
|
||||
if ct == "" {
|
||||
ct = "application/json"
|
||||
}
|
||||
req.Header.Set("Content-Type", ct)
|
||||
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not perform request: %v", err)
|
||||
|
||||
Reference in New Issue
Block a user