From fb58ff19195db997e924acb06f9241a1c6a6dca4 Mon Sep 17 00:00:00 2001 From: Steven Collins Date: Thu, 15 Jul 2021 11:51:01 -0500 Subject: [PATCH] CLOSES #35 Quoting issue (#39) * Implement and use template function for JSON. We build GraphQL queries with Go templates. We were using a built-in `js` template function for escaping arbitrary strings before using them as JSON strings. Which _almost_ works; it's not the intended use case for `js`. We actually needed a custom template function, as implemented here. Most of the changes in this commit are simply replacing `js` with `json` where templates are defined. The meat of the commit is in `query.go`. * Redo template strings not to use explicit quotes. Rather than the approach of the previous commit of the `json` template function doing something special when the output of Marshal is a JSON string, by stripping the beginning and ending quotation marks, simply don't use the quotation marks in the templates in the first place. * Add unit test for json template function. --- client/actions/channels/add_channel.go | 2 +- client/actions/channels/channel.go | 2 +- client/actions/channels/channel_by_name.go | 2 +- client/actions/channels/channels.go | 2 +- client/actions/channels/remove_channel.go | 2 +- client/actions/clusters/clusters_by_name.go | 2 +- client/actions/clusters/clusters_by_org_id.go | 2 +- .../clusters/delete_cluster_by_cluster_id.go | 2 +- client/actions/clusters/register_cluster.go | 2 +- client/actions/groups/add_group.go | 2 +- client/actions/groups/group_by_name.go | 2 +- client/actions/groups/group_clusters.go | 2 +- client/actions/groups/groups.go | 2 +- client/actions/groups/remove_group.go | 2 +- client/actions/groups/remove_group_by_name.go | 2 +- client/actions/query.go | 13 ++++-- client/actions/query_test.go | 40 ++++++++++++++++--- client/actions/resources/resource_content.go | 2 +- client/actions/resources/resources.go | 2 +- .../actions/resources/resources_by_cluster.go | 2 +- .../actions/subscriptions/add_subscription.go | 2 +- .../subscriptions/remove_subscription.go | 2 +- .../actions/subscriptions/set_subscription.go | 2 +- client/actions/subscriptions/subscriptions.go | 2 +- .../actions/versions/add_channel_version.go | 2 +- client/actions/versions/channel_version.go | 2 +- .../versions/channel_version_by_name.go | 2 +- .../versions/remove_channel_version.go | 2 +- client/auth/local/sign_in.go | 2 +- client/auth/local/sign_up.go | 2 +- client/web/client_test.go | 2 +- 31 files changed, 73 insertions(+), 38 deletions(-) diff --git a/client/actions/channels/add_channel.go b/client/actions/channels/add_channel.go index daafd7c..fb53c26 100644 --- a/client/actions/channels/add_channel.go +++ b/client/actions/channels/add_channel.go @@ -6,7 +6,7 @@ import ( const ( QueryAddChannel = "addChannel" - AddChannelVarTemplate = `{{define "vars"}}"orgId":"{{js .OrgID}}","name":"{{js .Name}}"{{end}}` + AddChannelVarTemplate = `{{define "vars"}}"orgId":{{json .OrgID}},"name":{{json .Name}}{{end}}` ) // AddChannelVariables are the variables specific to adding a group. diff --git a/client/actions/channels/channel.go b/client/actions/channels/channel.go index 32e9cda..88377a9 100644 --- a/client/actions/channels/channel.go +++ b/client/actions/channels/channel.go @@ -7,7 +7,7 @@ import ( const ( QueryChannel = "channel" - ChannelVarTemplate = `{{define "vars"}}"orgId":"{{js .OrgID}}","uuid":"{{js .UUID}}"{{end}}` + ChannelVarTemplate = `{{define "vars"}}"orgId":{{json .OrgID}},"uuid":{{json .UUID}}{{end}}` ) // ChannelVariables to query channel diff --git a/client/actions/channels/channel_by_name.go b/client/actions/channels/channel_by_name.go index 3cd412d..e2de6d3 100644 --- a/client/actions/channels/channel_by_name.go +++ b/client/actions/channels/channel_by_name.go @@ -7,7 +7,7 @@ import ( const ( QueryChannelByName = "channelByName" - ChannelByNameVarTemplate = `{{define "vars"}}"orgId":"{{js .OrgID}}","name":"{{js .Name}}"{{end}}` + ChannelByNameVarTemplate = `{{define "vars"}}"orgId":{{json .OrgID}},"name":{{json .Name}}{{end}}` ) // ChannelByNameVariables to query channel by name diff --git a/client/actions/channels/channels.go b/client/actions/channels/channels.go index fa7cfa5..dd8b66d 100644 --- a/client/actions/channels/channels.go +++ b/client/actions/channels/channels.go @@ -7,7 +7,7 @@ import ( const ( QueryChannels = "channels" - ChannelsVarTemplate = `{{define "vars"}}"orgId":"{{js .OrgID}}"{{end}}` + ChannelsVarTemplate = `{{define "vars"}}"orgId":{{json .OrgID}}{{end}}` ) type ChannelsVariables struct { diff --git a/client/actions/channels/remove_channel.go b/client/actions/channels/remove_channel.go index 47884fa..9e6eb30 100644 --- a/client/actions/channels/remove_channel.go +++ b/client/actions/channels/remove_channel.go @@ -6,7 +6,7 @@ import ( const ( QueryRemoveChannel = "removeChannel" - RemoveChannelVarTemplate = `{{define "vars"}}"orgId":"{{js .OrgID}}","uuid":"{{js .UUID}}"{{end}}` + RemoveChannelVarTemplate = `{{define "vars"}}"orgId":{{json .OrgID}},"uuid":{{json .UUID}}{{end}}` ) // RemoveChannelVariables are the variables specific to adding a group. diff --git a/client/actions/clusters/clusters_by_name.go b/client/actions/clusters/clusters_by_name.go index fba61b3..005afe3 100644 --- a/client/actions/clusters/clusters_by_name.go +++ b/client/actions/clusters/clusters_by_name.go @@ -7,7 +7,7 @@ import ( const ( QueryClusterByName = "clusterByName" - ClusterByNameVarTemplate = `{{define "vars"}}"orgId":"{{js .OrgID}}","clusterName":"{{js .ClusterName}}"{{end}}` + ClusterByNameVarTemplate = `{{define "vars"}}"orgId":{{json .OrgID}},"clusterName":{{json .ClusterName}}{{end}}` ) type ClusterByNameVariables struct { diff --git a/client/actions/clusters/clusters_by_org_id.go b/client/actions/clusters/clusters_by_org_id.go index 76a31a2..97f945a 100644 --- a/client/actions/clusters/clusters_by_org_id.go +++ b/client/actions/clusters/clusters_by_org_id.go @@ -7,7 +7,7 @@ import ( const ( QueryClustersByOrgID = "clustersByOrgId" - ClustersByOrgIDVarTemplate = `{{define "vars"}}"orgId":"{{js .OrgID}}"{{end}}` + ClustersByOrgIDVarTemplate = `{{define "vars"}}"orgId":{{json .OrgID}}{{end}}` ) type ClustersByOrgIDVariables struct { diff --git a/client/actions/clusters/delete_cluster_by_cluster_id.go b/client/actions/clusters/delete_cluster_by_cluster_id.go index 93ba284..48f6b9e 100644 --- a/client/actions/clusters/delete_cluster_by_cluster_id.go +++ b/client/actions/clusters/delete_cluster_by_cluster_id.go @@ -6,7 +6,7 @@ import ( const ( QueryDeleteClusterByClusterID = "deleteClusterByClusterId" - DeleteClusterByClusterIDVarTemplate = `{{define "vars"}}"orgId":"{{js .OrgID}}","clusterId":"{{js .ClusterID}}"{{end}}` + DeleteClusterByClusterIDVarTemplate = `{{define "vars"}}"orgId":{{json .OrgID}},"clusterId":{{json .ClusterID}}{{end}}` ) type DeleteClusterByClusterIDVariables struct { diff --git a/client/actions/clusters/register_cluster.go b/client/actions/clusters/register_cluster.go index d17ede7..5e178b3 100644 --- a/client/actions/clusters/register_cluster.go +++ b/client/actions/clusters/register_cluster.go @@ -12,7 +12,7 @@ import ( const ( QueryRegisterCluster = "registerCluster" - RegisterClusterVarTemplate = `{{define "vars"}}"orgId":"{{js .OrgID}}","registration":{{printf "%s" .Registration}}{{end}}` + RegisterClusterVarTemplate = `{{define "vars"}}"orgId":{{json .OrgID}},"registration":{{printf "%s" .Registration}}{{end}}` ) // RegisterClusterVariables are the variables specific to cluster registration. diff --git a/client/actions/groups/add_group.go b/client/actions/groups/add_group.go index 7fdc054..a3bb24e 100644 --- a/client/actions/groups/add_group.go +++ b/client/actions/groups/add_group.go @@ -6,7 +6,7 @@ import ( const ( QueryAddGroup = "addGroup" - AddGroupVarTemplate = `{{define "vars"}}"orgId":"{{js .OrgID}}","name":"{{js .Name}}"{{end}}` + AddGroupVarTemplate = `{{define "vars"}}"orgId":{{json .OrgID}},"name":{{json .Name}}{{end}}` ) // AddGroupVariables are the variables specific to adding a group. diff --git a/client/actions/groups/group_by_name.go b/client/actions/groups/group_by_name.go index b6b70e6..86406f8 100644 --- a/client/actions/groups/group_by_name.go +++ b/client/actions/groups/group_by_name.go @@ -7,7 +7,7 @@ import ( const ( QueryGroupByName = "groupByName" - GroupByNameVarTemplate = `{{define "vars"}}"orgId":"{{js .OrgID}}","name":"{{js .Name}}"{{end}}` + GroupByNameVarTemplate = `{{define "vars"}}"orgId":{{json .OrgID}},"name":{{json .Name}}{{end}}` ) type GroupByNameVariables struct { diff --git a/client/actions/groups/group_clusters.go b/client/actions/groups/group_clusters.go index c73be69..0edf46f 100644 --- a/client/actions/groups/group_clusters.go +++ b/client/actions/groups/group_clusters.go @@ -6,7 +6,7 @@ import ( const ( QueryGroupClusters = "groupClusters" - GroupClustersVarTemplate = `{{define "vars"}}"orgId":"{{js .OrgID}}","uuid":"{{js .UUID}}","clusters":[{{range $i,$e := .Clusters}}{{if gt $i 0}},{{end}}"{{js $e}}"{{end}}]{{end}}` + GroupClustersVarTemplate = `{{define "vars"}}"orgId":{{json .OrgID}},"uuid":{{json .UUID}},"clusters":[{{range $i,$e := .Clusters}}{{if gt $i 0}},{{end}}{{json $e}}{{end}}]{{end}}` ) // GroupClustersVariables are the variables specific to grouping clusters. diff --git a/client/actions/groups/groups.go b/client/actions/groups/groups.go index d52a50f..cd6065e 100644 --- a/client/actions/groups/groups.go +++ b/client/actions/groups/groups.go @@ -7,7 +7,7 @@ import ( const ( QueryGroups = "groups" - GroupsVarTemplate = `{{define "vars"}}"orgId":"{{js .OrgID}}"{{end}}` + GroupsVarTemplate = `{{define "vars"}}"orgId":{{json .OrgID}}{{end}}` ) type GroupsVariables struct { diff --git a/client/actions/groups/remove_group.go b/client/actions/groups/remove_group.go index 0b9cd65..52df4ab 100644 --- a/client/actions/groups/remove_group.go +++ b/client/actions/groups/remove_group.go @@ -4,7 +4,7 @@ import "github.com/IBM/satcon-client-go/client/actions" const ( QueryRemoveGroup = "removeGroup" - RemoveGroupVarTemplate = `{{define "vars"}}"orgId":"{{js .OrgID}}","uuid":"{{js .UUID}}"{{end}}` + RemoveGroupVarTemplate = `{{define "vars"}}"orgId":{{json .OrgID}},"uuid":{{json .UUID}}{{end}}` ) // RemoveGroupVariables are the variables specific to removing a group by name. diff --git a/client/actions/groups/remove_group_by_name.go b/client/actions/groups/remove_group_by_name.go index 44fc532..3a24ea6 100644 --- a/client/actions/groups/remove_group_by_name.go +++ b/client/actions/groups/remove_group_by_name.go @@ -4,7 +4,7 @@ import "github.com/IBM/satcon-client-go/client/actions" const ( QueryRemoveGroupByName = "removeGroupByName" - RemoveGroupByNameVarTemplate = `{{define "vars"}}"orgId":"{{js .OrgID}}","name":"{{js .Name}}"{{end}}` + RemoveGroupByNameVarTemplate = `{{define "vars"}}"orgId":{{json .OrgID}},"name":{{json .Name}}{{end}}` ) // RemoveGroupByNameVariables are the variables specific to removing a group by name. diff --git a/client/actions/query.go b/client/actions/query.go index 8d8cd44..d6aa4fc 100644 --- a/client/actions/query.go +++ b/client/actions/query.go @@ -2,6 +2,7 @@ package actions import ( "bytes" + "encoding/json" "errors" "fmt" "io" @@ -59,6 +60,11 @@ func BuildArgVarsList(args map[string]string) string { return "(" + strings.Join(argVarStrings, ", ") + ")" } +func JsonMarshalToString(v interface{}) (string, error) { + bytes, err := json.Marshal(v) + return string(bytes), err +} + //BuildRequest builds the request and it sets the headers func BuildRequest(payload io.Reader, endpoint string, authClient auth.AuthClient) (*http.Request, error) { req, _ := http.NewRequest(http.MethodPost, endpoint, payload) @@ -82,16 +88,17 @@ func BuildRequest(payload io.Reader, endpoint string, authClient auth.AuthClient // e.g.: // `{{define "vars"}}"var_1":"{{.Var1}},"var2":"{{.Var2}}"{{end}}` func BuildRequestBody(requestTemplate string, vars interface{}, funcs template.FuncMap) (io.Reader, RequestBodyError) { - // First we scan to make sure all variables are escaped using the "js" built-in function - reString := `\{\{\w*(?:js){0}\w*\.` + // First we scan to make sure all variables are escaped using the "json" function + reString := `\{\{\w*(?:json){0}\w*\.` re, _ := regexp.Compile(reString) if re.MatchString(requestTemplate) { - return nil, errors.New("All variables must be escaped using 'js' built-in") + return nil, errors.New("All variables must be escaped using 'json' template function") } defaultFuncs := template.FuncMap{ "buildArgsList": BuildArgsList, "buildArgVarsList": BuildArgVarsList, + "json": JsonMarshalToString, } // Merge in user-supplied functions diff --git a/client/actions/query_test.go b/client/actions/query_test.go index 10af606..da77a05 100644 --- a/client/actions/query_test.go +++ b/client/actions/query_test.go @@ -30,6 +30,34 @@ var _ = Describe("Query", func() { } }) + Describe("json template function", func() { + type Special struct { + A string + B string + C string + } + + FIt("Correctly escapes special characters", func() { + testSpecial := Special{ + A: `'apostrophes'`, + B: `"quotes"`, + C: `\backslashes\`, + } + funcs := template.FuncMap{ + "json": JsonMarshalToString, + } + + tmpl, err := template.New("test").Funcs(funcs).Parse("{{json .A}} {{json .B}} {{json .C}}") + Expect(err).NotTo(HaveOccurred()) + + buf := &bytes.Buffer{} + err = tmpl.Execute(buf, testSpecial) + Expect(err).NotTo(HaveOccurred()) + finalBytes, err := ioutil.ReadAll(buf) + Expect(err).NotTo(HaveOccurred()) + Expect(finalBytes).To(Equal([]byte(`"'apostrophes'" "\"quotes\"" "\\backslashes\\"`))) + }) + }) Describe("BuildArgsList", func() { It("Returns a string containing a list delimited by ', '", func() { argList := BuildArgsList(argMap) @@ -147,7 +175,7 @@ var _ = Describe("Query", func() { ) BeforeEach(func() { - requestTemplate = `{{define "vars"}}"first":"{{js .First}}","last":"{{js .Last}}"{{end}}` + requestTemplate = `{{define "vars"}}"first":{{json .First}},"last":{{json .Last}}{{end}}` vars = requestVars{ First: "Don", Last: "Quixote", @@ -219,7 +247,7 @@ var _ = Describe("Query", func() { Context("When additional helper functions are passed in", func() { BeforeEach(func() { - requestTemplate = `{{define "vars"}}"first":"{{js (toUpper .First)}}"{{end}}` + requestTemplate = `{{define "vars"}}"first":{{json (toUpper .First)}}{{end}}` funcs = template.FuncMap{ "toUpper": strings.ToUpper, } @@ -234,9 +262,9 @@ var _ = Describe("Query", func() { }) }) - Context("When the variable template does not escape js for all variables", func() { + Context("When the variable template does not escape json for all variables", func() { BeforeEach(func() { - requestTemplate = `{{define "vars"}}"first":"{{js .First}}","last":"{{.Last}}"{{end}}` + requestTemplate = `{{define "vars"}}"first":{{json .First}},"last":"{{.Last}}"{{end}}` }) It("Returns nil and an error", func() { @@ -248,7 +276,7 @@ var _ = Describe("Query", func() { Context("When the variable template is not valid", func() { BeforeEach(func() { - requestTemplate = `{{define "vars"}}{{js .First}}` + requestTemplate = `{{define "vars"}}{{json .First}}` }) It("Returns nil and an error", func() { @@ -260,7 +288,7 @@ var _ = Describe("Query", func() { Context("When the template references variables not part of the struct", func() { BeforeEach(func() { - requestTemplate = `{{define "vars"}}"first":"{{js .Foo}}"{{end}}` + requestTemplate = `{{define "vars"}}"first":{{json .Foo}}{{end}}` }) It("Returns nil and an error", func() { diff --git a/client/actions/resources/resource_content.go b/client/actions/resources/resource_content.go index 8207916..a9d0313 100644 --- a/client/actions/resources/resource_content.go +++ b/client/actions/resources/resource_content.go @@ -7,7 +7,7 @@ import ( const ( QueryResourceContent = "resourceContent" - ResourceContentVarTemplate = `{{define "vars"}}"orgId":"{{js .OrgID}}", "clusterId":"{{js .ClusterID}}", "resourceSelfLink":"{{js .ResourceSelfLink}}"{{end}}` + ResourceContentVarTemplate = `{{define "vars"}}"orgId":{{json .OrgID}}, "clusterId":{{json .ClusterID}}, "resourceSelfLink":{{json .ResourceSelfLink}}{{end}}` ) // ResourceContentVariables variable to query resources for specified cluster diff --git a/client/actions/resources/resources.go b/client/actions/resources/resources.go index 7cc633d..45ccf7c 100644 --- a/client/actions/resources/resources.go +++ b/client/actions/resources/resources.go @@ -7,7 +7,7 @@ import ( const ( QueryResources = "resources" - ResourcesVarTemplate = `{{define "vars"}}"orgId":"{{js .OrgID}}"{{end}}` + ResourcesVarTemplate = `{{define "vars"}}"orgId":{{json .OrgID}}{{end}}` ) // ResourcesVariables variable to query resources for specified cluster diff --git a/client/actions/resources/resources_by_cluster.go b/client/actions/resources/resources_by_cluster.go index 58a907f..3d5784f 100644 --- a/client/actions/resources/resources_by_cluster.go +++ b/client/actions/resources/resources_by_cluster.go @@ -7,7 +7,7 @@ import ( const ( QueryResourcesByCluster = "resourcesByCluster" - ResourcesByClusterVarTemplate = `{{define "vars"}}"orgId":"{{js .OrgID}}","clusterId":"{{js .ClusterID}}", "filter":"{{js .Filter}}","limit":{{js .Limit}}{{end}}` + ResourcesByClusterVarTemplate = `{{define "vars"}}"orgId":{{json .OrgID}},"clusterId":{{json .ClusterID}}, "filter":{{json .Filter}},"limit":{{json .Limit}}{{end}}` ) // ResourcesByClusterVariables variable to query resources for specified cluster diff --git a/client/actions/subscriptions/add_subscription.go b/client/actions/subscriptions/add_subscription.go index 65b7e35..45f8d60 100644 --- a/client/actions/subscriptions/add_subscription.go +++ b/client/actions/subscriptions/add_subscription.go @@ -6,7 +6,7 @@ import ( const ( QueryAddSubscription = "addSubscription" - AddSubscriptionVarTemplate = `{{define "vars"}}"orgId":"{{js .OrgID}}","name":"{{js .Name}}","groups":[{{range $i,$e := .Groups}}{{if gt $i 0}},{{end}}"{{js $e}}"{{end}}],"channelUuid":"{{js .ChannelUUID}}","versionUuid":"{{js .VersionUUID}}"{{end}}` + AddSubscriptionVarTemplate = `{{define "vars"}}"orgId":{{json .OrgID}},"name":{{json .Name}},"groups":[{{range $i,$e := .Groups}}{{if gt $i 0}},{{end}}{{json $e}}{{end}}],"channelUuid":{{json .ChannelUUID}},"versionUuid":{{json .VersionUUID}}{{end}}` ) type AddSubscriptionVariables struct { diff --git a/client/actions/subscriptions/remove_subscription.go b/client/actions/subscriptions/remove_subscription.go index 81b98fa..da282b2 100644 --- a/client/actions/subscriptions/remove_subscription.go +++ b/client/actions/subscriptions/remove_subscription.go @@ -6,7 +6,7 @@ import ( const ( QueryRemoveSubscription = "removeSubscription" - RemoveSubscriptionVarTemplate = `{{define "vars"}}"orgId":"{{js .OrgID}}","uuid":"{{js .UUID}}"{{end}}` + RemoveSubscriptionVarTemplate = `{{define "vars"}}"orgId":{{json .OrgID}},"uuid":{{json .UUID}}{{end}}` ) // RemoveSubscriptionVariables are the variables specific to adding a group. diff --git a/client/actions/subscriptions/set_subscription.go b/client/actions/subscriptions/set_subscription.go index 0b801a0..83d1d72 100644 --- a/client/actions/subscriptions/set_subscription.go +++ b/client/actions/subscriptions/set_subscription.go @@ -6,7 +6,7 @@ import ( const ( QuerySetSubscription = "setSubscription" - SetSubscriptionVarTemplate = `{{define "vars"}}"orgId":"{{js .OrgID}}","uuid":"{{js .UUID}}","versionUuid":"{{js .VersionUUID}}"{{end}}` + SetSubscriptionVarTemplate = `{{define "vars"}}"orgId":{{json .OrgID}},"uuid":{{json .UUID}},"versionUuid":{{json .VersionUUID}}{{end}}` ) type SetSubscriptionVariables struct { diff --git a/client/actions/subscriptions/subscriptions.go b/client/actions/subscriptions/subscriptions.go index e3731d2..0fe28f4 100644 --- a/client/actions/subscriptions/subscriptions.go +++ b/client/actions/subscriptions/subscriptions.go @@ -9,7 +9,7 @@ const ( //QuerySubscriptions specifies the query QuerySubscriptions = "subscriptions" //SubscriptionsVarTemplate is the template used to create the graphql query - SubscriptionsVarTemplate = `{{define "vars"}}"orgId":"{{js .OrgID}}"{{end}}` + SubscriptionsVarTemplate = `{{define "vars"}}"orgId":{{json .OrgID}}{{end}}` ) //SubscriptionsVariables are the variables used for the subscription query diff --git a/client/actions/versions/add_channel_version.go b/client/actions/versions/add_channel_version.go index 86d6ac9..73764dd 100644 --- a/client/actions/versions/add_channel_version.go +++ b/client/actions/versions/add_channel_version.go @@ -7,7 +7,7 @@ import ( const ( ContentType = "application/yaml" QueryAddChannelVersion = "addChannelVersion" - AddChannelVersionVarTemplate = `{{define "vars"}}"orgId":"{{js .OrgID}}","channelUuid":"{{js .ChannelUUID}}","name":"{{js .Name}}","type":"{{js .ContentType}}","content":"{{js .Content}}","description":"{{js .Description}}"{{end}}` + AddChannelVersionVarTemplate = `{{define "vars"}}"orgId":{{json .OrgID}},"channelUuid":{{json .ChannelUUID}},"name":{{json .Name}},"type":{{json .ContentType}},"content":{{json .Content}},"description":{{json .Description}}{{end}}` ) // AddChannelVersionVariables to create addChannelVersion graphql request diff --git a/client/actions/versions/channel_version.go b/client/actions/versions/channel_version.go index 842e3e6..6b8b096 100644 --- a/client/actions/versions/channel_version.go +++ b/client/actions/versions/channel_version.go @@ -9,7 +9,7 @@ const ( //QueryChannelVersion specifies the query QueryChannelVersion = "channelVersion" // ChannelVersionVarTemplate is the template used to create the graphql query - ChannelVersionVarTemplate = `{{define "vars"}}"orgId":"{{js .OrgID}}","channelUuid":"{{js .ChannelUUID}}","versionUuid":"{{js .VersionUUID}}"{{end}}` + ChannelVersionVarTemplate = `{{define "vars"}}"orgId":{{json .OrgID}},"channelUuid":{{json .ChannelUUID}},"versionUuid":{{json .VersionUUID}}{{end}}` ) // ChannelVersionVariables are the variables used for the subscription query diff --git a/client/actions/versions/channel_version_by_name.go b/client/actions/versions/channel_version_by_name.go index ee62ccb..88b5ca4 100644 --- a/client/actions/versions/channel_version_by_name.go +++ b/client/actions/versions/channel_version_by_name.go @@ -9,7 +9,7 @@ const ( //QueryChannelVersionByName specifies the query QueryChannelVersionByName = "channelVersionByName" // ChannelVersionByNameVarTemplate is the template used to create the graphql query - ChannelVersionByNameVarTemplate = `{{define "vars"}}"orgId":"{{js .OrgID}}","channelName":"{{js .ChannelName}}","versionName":"{{js .VersionName}}"{{end}}` + ChannelVersionByNameVarTemplate = `{{define "vars"}}"orgId":{{json .OrgID}},"channelName":{{json .ChannelName}},"versionName":{{json .VersionName}}{{end}}` ) //SubscriptionsVariables are the variables used for the subscription query diff --git a/client/actions/versions/remove_channel_version.go b/client/actions/versions/remove_channel_version.go index f1130ff..d687040 100644 --- a/client/actions/versions/remove_channel_version.go +++ b/client/actions/versions/remove_channel_version.go @@ -6,7 +6,7 @@ import ( const ( QueryRemoveChannelVersion = "removeChannelVersion" - RemoveChannelVersionVarTemplate = `{{define "vars"}}"orgId":"{{js .OrgID}}","uuid":"{{js .UUID}}"{{end}}` + RemoveChannelVersionVarTemplate = `{{define "vars"}}"orgId":{{json .OrgID}},"uuid":{{json .UUID}}{{end}}` ) // RemoveChannelVersionVariables are the variables specific to adding a group. diff --git a/client/auth/local/sign_in.go b/client/auth/local/sign_in.go index 192ac19..333afec 100644 --- a/client/auth/local/sign_in.go +++ b/client/auth/local/sign_in.go @@ -8,7 +8,7 @@ import ( const ( MutationSignIn = "signIn" - SignInVarTemplate = `{{define "vars"}}"login":"{{js .Login}}","password":"{{js .Password}}"{{end}}` + SignInVarTemplate = `{{define "vars"}}"login":{{json .Login}},"password":{{json .Password}}{{end}}` ) // AddSignInVariables are the variables specific to log in a user. diff --git a/client/auth/local/sign_up.go b/client/auth/local/sign_up.go index 022165b..c560231 100644 --- a/client/auth/local/sign_up.go +++ b/client/auth/local/sign_up.go @@ -8,7 +8,7 @@ import ( const ( MutationSignUp = "signUp" - SignUpVarTemplate = `{{define "vars"}}"username":"{{js .Username}}","email":"{{js .Email}}","password":"{{js .Password}}","orgName":"{{js .OrgName}}","role":"{{js .Role}}"{{end}}` + SignUpVarTemplate = `{{define "vars"}}"username":{{json .Username}},"email":{{json .Email}},"password":{{json .Password}},"orgName":{{json .OrgName}},"role":{{json .Role}}{{end}}` ) // AddSignUpVariables are the variables specific to adding a user. diff --git a/client/web/client_test.go b/client/web/client_test.go index 4251021..b9b5474 100644 --- a/client/web/client_test.go +++ b/client/web/client_test.go @@ -76,7 +76,7 @@ var _ = Describe("Client", func() { h.DoReturns(response, nil) // Setup the template - requestTemplate = `{{define "vars"}}"name":"{{js .Name}}"{{end}}` + requestTemplate = `{{define "vars"}}"name":{{json .Name}}{{end}}` vars = QueryVars{ Name: "foo", }