Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

base: handle unknown certificate authority error #80

Merged
merged 1 commit into from
Oct 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions base/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ package base
import (
"bytes"
"context"
"crypto/x509"
"encoding/base64"
"encoding/json"
"fmt"
Expand Down Expand Up @@ -309,6 +310,10 @@ func makeNetRequest(ctx context.Context, req *http.Request, rt http.RoundTripper
default:
method := req.Header.Get("X-Blazer-Method")
blog.V(2).Infof(">> %s uri: %v err: %v", method, req.URL, err)
switch err.(type) {
case x509.UnknownAuthorityError:
return nil, err
}
return nil, b2err{
msg: err.Error(),
retry: 1,
Expand Down
24 changes: 24 additions & 0 deletions base/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ package base
import (
"bytes"
"crypto/sha1"
"crypto/tls"
"crypto/x509"
"encoding/json"
"fmt"
"io"
"net/http"
"os"
"reflect"
"strings"
Expand Down Expand Up @@ -439,6 +442,27 @@ func TestDeadlineExceededContextCancelsHTTPRequest(t *testing.T) {
}
}

func TestUnknownCA(t *testing.T) {
id := os.Getenv(apiID)
key := os.Getenv(apiKey)
if id == "" || key == "" {
t.Skipf("B2_ACCOUNT_ID or B2_SECRET_KEY unset; skipping integration tests")
}
ctx := context.Background()

tport := &http.Transport{
TLSClientConfig: &tls.Config{RootCAs: x509.NewCertPool()},
}

_, err := AuthorizeAccount(ctx, id, key, Transport(tport))
if err == nil {
t.Error("expected an error, got none")
}
if Action(err) != Punt {
t.Errorf("Action(%v): got %v, want Punt", err, Action(err))
}
}

func compareFileAndInfo(t *testing.T, info *FileInfo, name, sha1 string, imap map[string]string) {
if info.Name != name {
t.Errorf("got %q, want %q", info.Name, name)
Expand Down