Skip to content

Commit

Permalink
Merge pull request #80 from garrmcnu/unknown-authority-error
Browse files Browse the repository at this point in the history
base: handle unknown certificate authority error
  • Loading branch information
kurin committed Oct 30, 2021
2 parents 9d61c73 + 3e939bc commit c089402
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
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

0 comments on commit c089402

Please sign in to comment.