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

add fcmOptions in WebpushConfig #185

Merged
merged 10 commits into from Nov 13, 2018
@@ -1,9 +1,6 @@
language: go

go:
- 1.6.x
- 1.7.x
- 1.8.x
- 1.9.x
- "1.10.x"
- master
@@ -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.
@@ -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

@@ -27,7 +27,6 @@ import (

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

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

@@ -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.
@@ -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{})
@@ -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"
)

@@ -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",
},
@@ -254,6 +256,9 @@ var validMessages = []struct {
"k1": "v1",
"k2": "v2",
},
"fcmOptions": map[string]interface{}{
"link": "https://link.com",
},
},
"topic": "test-topic",
},
@@ -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 {
@@ -16,6 +16,7 @@ package messaging

import (
"fmt"
"net/url"
"regexp"
"strings"
)
@@ -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
}

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.