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
11 changes: 2 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
language: go

go:
- 1.6.x
- 1.7.x
- 1.8.x
- 1.9.x
- "1.10.x"
- master
Expand All @@ -18,16 +15,12 @@ matrix:

go_import_path: firebase.google.com/go

before_install:
# Golint requires Go 1.7 or later.
- if ! [[ "$TRAVIS_GO_VERSION" =~ ^1\.6\.([0-9]+|x)$ ]]; then go get github.com/golang/lint/golint; fi

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

script:
- if ! [[ "$TRAVIS_GO_VERSION" =~ ^1\.6\.([0-9]+|x)+$ ]]; then golint -set_exit_status $(go list ./...); fi
- golint -set_exit_status $(go list ./...)
- ./.travis.gofmt.sh
- go test -v -race -test.short ./... # Run tests with the race detector.
- go vet -v ./... # Run Go static analyzer.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ requests, code review feedback, and also pull requests.

## Supported Go Versions

We support Go v1.6 and higher.
We support Go v1.9 and higher.
[Continuous integration](https://travis-ci.org/firebase/firebase-admin-go) system
tests the code on Go v1.6 through v1.10.
tests the code on Go v1.9 through v1.10.

## Documentation

Expand Down
7 changes: 6 additions & 1 deletion messaging/messaging.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (

"firebase.google.com/go/internal"
"golang.org/x/net/context"

"google.golang.org/api/transport"
)

Expand Down Expand Up @@ -225,6 +224,7 @@ type WebpushConfig struct {
Headers map[string]string `json:"headers,omitempty"`
Data map[string]string `json:"data,omitempty"`
Notification *WebpushNotification `json:"notification,omitempty"`
FcmOptions *WebpushFcmOptions `json:"fcmOptions,omitempty"`
}

// WebpushNotificationAction represents an action that can be performed upon receiving a WebPush notification.
Expand Down Expand Up @@ -257,6 +257,11 @@ type WebpushNotification struct {
CustomData map[string]interface{}
}

// WebpushFcmOptions Options for features provided by the FCM SDK for Web.
type WebpushFcmOptions struct {
Link string `json:"link,omitempty"`
}

// standardFields creates a map containing all the fields except the custom data.
func (n *WebpushNotification) standardFields() map[string]interface{} {
m := make(map[string]interface{})
Expand Down
35 changes: 33 additions & 2 deletions messaging/messaging_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ import (
"testing"
"time"

"golang.org/x/net/context"

"firebase.google.com/go/internal"
"golang.org/x/net/context"
"google.golang.org/api/option"
)

Expand Down Expand Up @@ -226,6 +225,9 @@ var validMessages = []struct {
Vibrate: []int{100, 200, 100},
CustomData: map[string]interface{}{"k1": "v1", "k2": "v2"},
},
FcmOptions: &WebpushFcmOptions{
Link: "https://link.com",
},
},
Topic: "test-topic",
},
Expand Down Expand Up @@ -254,6 +256,9 @@ var validMessages = []struct {
"k1": "v1",
"k2": "v2",
},
"fcmOptions": map[string]interface{}{
"link": "https://link.com",
},
},
"topic": "test-topic",
},
Expand Down Expand Up @@ -593,6 +598,32 @@ var invalidMessages = []struct {
},
want: `multiple specifications for the key "dir"`,
},
{
name: "InvalidWebpushFcmOptionsLink",
req: &Message{
Webpush: &WebpushConfig{
Notification: &WebpushNotification{},
FcmOptions: &WebpushFcmOptions{
Link: "link",
},
},
Topic: "topic",
},
want: `invalid link URL: "link"`,
},
{
name: "InvalidWebpushFcmOptionsLinkScheme",
req: &Message{
Webpush: &WebpushConfig{
Notification: &WebpushNotification{},
FcmOptions: &WebpushFcmOptions{
Link: "http://link.com",
},
},
Topic: "topic",
},
want: `invalid link URL: "http://link.com"; want scheme: "https"`,
},
}

var invalidTopicMgtArgs = []struct {
Expand Down
10 changes: 10 additions & 0 deletions messaging/messaging_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package messaging

import (
"fmt"
"net/url"
"regexp"
"strings"
)
Expand Down Expand Up @@ -145,6 +146,15 @@ func validateWebpushConfig(webpush *WebpushConfig) error {
return fmt.Errorf("multiple specifications for the key %q", k)
}
}
if webpush.FcmOptions != nil {
link := webpush.FcmOptions.Link
p, err := url.ParseRequestURI(link)
if err != nil {
return fmt.Errorf("invalid link URL: %q", link)
} else if p.Scheme != "https" {
return fmt.Errorf("invalid link URL: %q; want scheme: %q", link, "https")
}
}
return nil
}

Expand Down