-
Notifications
You must be signed in to change notification settings - Fork 949
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enable setup common name whitelist for tls checking
Signed-off-by: Frank Yang <[email protected]>
- Loading branch information
Showing
12 changed files
with
324 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package client | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
|
||
"github.com/alibaba/pouch/apis/types" | ||
) | ||
|
||
// RegistryLogin authenticates the server with a given registry to login. | ||
func (client *APIClient) RegistryLogin(ctx context.Context, auth *types.AuthConfig) (*types.AuthResponse, error) { | ||
resp, err := client.post(ctx, "/auth", nil, auth, nil) | ||
if err != nil || resp.StatusCode == http.StatusUnauthorized { | ||
return nil, err | ||
} | ||
|
||
authResp := &types.AuthResponse{} | ||
err = decodeBody(authResp, resp.Body) | ||
ensureCloseReader(resp) | ||
|
||
return authResp, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package client | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"io/ioutil" | ||
"net/http" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/alibaba/pouch/apis/types" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestRegistryLoginError(t *testing.T) { | ||
client := &APIClient{ | ||
HTTPCli: newMockClient(errorMockResponse(http.StatusInternalServerError, "Server error")), | ||
} | ||
loginConfig := types.AuthConfig{} | ||
_, err := client.RegistryLogin(context.Background(), &loginConfig) | ||
if err == nil || !strings.Contains(err.Error(), "Server error") { | ||
t.Fatalf("expected a Server Error, got %v", err) | ||
} | ||
} | ||
|
||
func TestRegistryLogin(t *testing.T) { | ||
expectedURL := "/auth" | ||
|
||
httpClient := newMockClient(func(req *http.Request) (*http.Response, error) { | ||
if !strings.HasPrefix(req.URL.Path, expectedURL) { | ||
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) | ||
} | ||
if req.Header.Get("Content-Type") == "application/json" { | ||
loginConfig := types.AuthConfig{} | ||
if err := json.NewDecoder(req.Body).Decode(&loginConfig); err != nil { | ||
return nil, fmt.Errorf("failed to parse json: %v", err) | ||
} | ||
} | ||
auth, err := json.Marshal(types.AuthResponse{ | ||
IdentityToken: "aaa", | ||
Status: "bbb", | ||
}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &http.Response{ | ||
StatusCode: http.StatusOK, | ||
Body: ioutil.NopCloser(bytes.NewReader([]byte(auth))), | ||
}, nil | ||
}) | ||
|
||
client := &APIClient{ | ||
HTTPCli: httpClient, | ||
} | ||
|
||
res, err := client.RegistryLogin(context.Background(), &types.AuthConfig{}) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
assert.Equal(t, res.IdentityToken, "aaa") | ||
assert.Equal(t, res.Status, "bbb") | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package client | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/alibaba/pouch/apis/types" | ||
) | ||
|
||
// SystemInfo requests daemon for system info. | ||
func (client *APIClient) SystemInfo(ctx context.Context) (*types.SystemInfo, error) { | ||
resp, err := client.get(ctx, "/info", nil, nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
info := &types.SystemInfo{} | ||
err = decodeBody(info, resp.Body) | ||
ensureCloseReader(resp) | ||
|
||
return info, err | ||
} |
Oops, something went wrong.