Skip to content
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
28 changes: 25 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,30 @@
language: go

go:
- 1.7.x
- 1.8.x
- 1.9.x
- "1.10.x"
- master

matrix:
# Build OK if fails on unstable development versions of Go.
allow_failures:
- go: master
# Don't wait for tests to finish on allow_failures.
# Mark the build finished if tests pass on other versions of Go.
fast_finish: true

go_import_path: firebase.google.com/go

before_install:
- go get github.com/golang/lint/golint
- go get github.com/golang/lint/golint # Golint requires Go 1.6 or later.

install:
# Prior to golang 1.8, this can trigger an error for packages containing only tests.
- go get -t -v $(go list ./... | grep -v integration)

script:
- golint -set_exit_status $(go list ./...)
- go test -v -test.short ./...

- go test -v -race -test.short ./... # Run tests with the race detector.
- go vet -v ./... # Run Go static analyzer.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

-

# v2.6.0

- [changed] Improved error handling in FCM by mapping more server-side
errors to client-side error codes.
- [added] Added the `db` package for interacting with the Firebase database.

# v2.5.0

- [changed] Import context from `golang.org/x/net` for 1.6 compatibility
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[![Build Status](https://travis-ci.org/firebase/firebase-admin-go.svg?branch=master)](https://travis-ci.org/firebase/firebase-admin-go)
[![GoDoc](https://godoc.org/firebase.google.com/go?status.svg)](https://godoc.org/firebase.google.com/go)
[![Go Report Card](https://goreportcard.com/badge/github.com/firebase/firebase-admin-go)](https://goreportcard.com/report/github.com/firebase/firebase-admin-go)

# Firebase Admin Go SDK

Expand Down Expand Up @@ -43,6 +44,9 @@ requests, code review feedback, and also pull requests.

* [Setup Guide](https://firebase.google.com/docs/admin/setup/)
* [Authentication Guide](https://firebase.google.com/docs/auth/admin/)
* [Cloud Firestore](https://firebase.google.com/docs/firestore/)
* [Cloud Messaging Guide](https://firebase.google.com/docs/cloud-messaging/admin/)
* [Storage Guide](https://firebase.google.com/docs/storage/admin/start)
* [API Reference](https://godoc.org/firebase.google.com/go)
* [Release Notes](https://firebase.google.com/support/release-notes/admin/go)

Expand Down
4 changes: 2 additions & 2 deletions auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package auth

import (
"context"
"crypto/rsa"
"crypto/x509"
"encoding/json"
Expand All @@ -25,7 +26,6 @@ import (
"strings"

"firebase.google.com/go/internal"
"golang.org/x/net/context"
"google.golang.org/api/identitytoolkit/v3"
"google.golang.org/api/transport"
)
Expand Down Expand Up @@ -78,7 +78,7 @@ type signer interface {
// NewClient creates a new instance of the Firebase Auth Client.
//
// This function can only be invoked from within the SDK. Client applications should access the
// the Auth service through firebase.App.
// Auth service through firebase.App.
func NewClient(ctx context.Context, c *internal.AuthConfig) (*Client, error) {
var (
err error
Expand Down
2 changes: 1 addition & 1 deletion auth/auth_appengine.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package auth

import (
"golang.org/x/net/context"
"context"

"google.golang.org/appengine"
)
Expand Down
2 changes: 1 addition & 1 deletion auth/auth_std.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package auth

import "golang.org/x/net/context"
import "context"

func newSigner(ctx context.Context) (signer, error) {
return serviceAcctSigner{}, nil
Expand Down
2 changes: 1 addition & 1 deletion auth/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package auth

import (
"context"
"encoding/json"
"errors"
"fmt"
Expand All @@ -25,7 +26,6 @@ import (
"testing"
"time"

"golang.org/x/net/context"
"golang.org/x/oauth2/google"

"google.golang.org/api/option"
Expand Down
14 changes: 14 additions & 0 deletions auth/jwt_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2017 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package auth

import (
Expand Down
2 changes: 1 addition & 1 deletion auth/user_mgt.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package auth

import (
"context"
"encoding/json"
"fmt"
"net/http"
Expand All @@ -23,7 +24,6 @@ import (
"strings"
"time"

"golang.org/x/net/context"
"google.golang.org/api/identitytoolkit/v3"
"google.golang.org/api/iterator"
)
Expand Down
14 changes: 7 additions & 7 deletions auth/user_mgt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package auth

import (
"bytes"
"context"
"encoding/json"
"fmt"
"io/ioutil"
Expand All @@ -28,7 +29,6 @@ import (

"firebase.google.com/go/internal"

"golang.org/x/net/context"
"golang.org/x/oauth2"
"google.golang.org/api/identitytoolkit/v3"
"google.golang.org/api/iterator"
Expand Down Expand Up @@ -167,9 +167,9 @@ func TestListUsers(t *testing.T) {
defer s.Close()

want := []*ExportedUserRecord{
&ExportedUserRecord{UserRecord: testUser, PasswordHash: "passwordhash1", PasswordSalt: "salt1"},
&ExportedUserRecord{UserRecord: testUser, PasswordHash: "passwordhash2", PasswordSalt: "salt2"},
&ExportedUserRecord{UserRecord: testUser, PasswordHash: "passwordhash3", PasswordSalt: "salt3"},
{UserRecord: testUser, PasswordHash: "passwordhash1", PasswordSalt: "salt1"},
{UserRecord: testUser, PasswordHash: "passwordhash2", PasswordSalt: "salt2"},
{UserRecord: testUser, PasswordHash: "passwordhash3", PasswordSalt: "salt3"},
}

testIterator := func(iter *UserIterator, token string, req map[string]interface{}) {
Expand Down Expand Up @@ -574,9 +574,9 @@ func TestInvalidSetCustomClaims(t *testing.T) {
func TestSetCustomClaims(t *testing.T) {
cases := []map[string]interface{}{
nil,
map[string]interface{}{},
map[string]interface{}{"admin": true},
map[string]interface{}{"admin": true, "package": "gold"},
{},
{"admin": true},
{"admin": true, "package": "gold"},
}

resp := `{
Expand Down
107 changes: 107 additions & 0 deletions db/auth_override_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
// Copyright 2018 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package db

import (
"testing"

"golang.org/x/net/context"
)

func TestAuthOverrideGet(t *testing.T) {
mock := &mockServer{Resp: "data"}
srv := mock.Start(aoClient)
defer srv.Close()

ref := aoClient.NewRef("peter")
var got string
if err := ref.Get(context.Background(), &got); err != nil {
t.Fatal(err)
}
if got != "data" {
t.Errorf("Ref(AuthOverride).Get() = %q; want = %q", got, "data")
}
checkOnlyRequest(t, mock.Reqs, &testReq{
Method: "GET",
Path: "/peter.json",
Query: map[string]string{"auth_variable_override": testAuthOverrides},
})
}

func TestAuthOverrideSet(t *testing.T) {
mock := &mockServer{}
srv := mock.Start(aoClient)
defer srv.Close()

ref := aoClient.NewRef("peter")
want := map[string]interface{}{"name": "Peter Parker", "age": float64(17)}
if err := ref.Set(context.Background(), want); err != nil {
t.Fatal(err)
}
checkOnlyRequest(t, mock.Reqs, &testReq{
Method: "PUT",
Body: serialize(want),
Path: "/peter.json",
Query: map[string]string{"auth_variable_override": testAuthOverrides, "print": "silent"},
})
}

func TestAuthOverrideQuery(t *testing.T) {
mock := &mockServer{Resp: "data"}
srv := mock.Start(aoClient)
defer srv.Close()

ref := aoClient.NewRef("peter")
var got string
if err := ref.OrderByChild("foo").Get(context.Background(), &got); err != nil {
t.Fatal(err)
}
if got != "data" {
t.Errorf("Ref(AuthOverride).OrderByChild() = %q; want = %q", got, "data")
}
checkOnlyRequest(t, mock.Reqs, &testReq{
Method: "GET",
Path: "/peter.json",
Query: map[string]string{
"auth_variable_override": testAuthOverrides,
"orderBy": "\"foo\"",
},
})
}

func TestAuthOverrideRangeQuery(t *testing.T) {
mock := &mockServer{Resp: "data"}
srv := mock.Start(aoClient)
defer srv.Close()

ref := aoClient.NewRef("peter")
var got string
if err := ref.OrderByChild("foo").StartAt(1).EndAt(10).Get(context.Background(), &got); err != nil {
t.Fatal(err)
}
if got != "data" {
t.Errorf("Ref(AuthOverride).OrderByChild() = %q; want = %q", got, "data")
}
checkOnlyRequest(t, mock.Reqs, &testReq{
Method: "GET",
Path: "/peter.json",
Query: map[string]string{
"auth_variable_override": testAuthOverrides,
"orderBy": "\"foo\"",
"startAt": "1",
"endAt": "10",
},
})
}
Loading