akshaykarle / go-mongodbatlas

A Go client library for the MongoDB Atlas API
GNU General Public License v3.0
16 stars 20 forks source link

CIDR block / not escaped in Whitelist Get #1

Closed jagregory closed 6 years ago

jagregory commented 6 years ago

I suspect this is the root cause of: https://github.com/akshaykarle/terraform-provider-mongodbatlas/issues/16

According to the MongoDB Atlas docs, the / in CIDR blocks should be URL encoded when requesting Whitelist resources: https://docs.atlas.mongodb.com/reference/api/whitelist/#get-the-entry-for-a-specific-address-in-a-group-s-ip-whitelist

If the entry includes a subnet mask, use the URL-encoded value for the forward slash (/). For example, for an entry of 1.2.3.4/5, use 1.2.3.4%2F5.

Looking at the whitelist tests, the mux stub is being set up incorrectly without the slash encoded.

mux.HandleFunc("/api/atlas/v1.0/groups/123/whitelist/10.15.0.0/16", func(w http.ResponseWriter, r *http.Request) {
  assertMethod(t, "GET", r)
  fmt.Fprintf(w, `{"cidrBlock":"10.15.0.0/16","comment":"test","groupId":"123","ipAddress":"10.15.0.1"}`)
})
akshaykarle commented 6 years ago

Hey @jagregory looking into this now. Although I've not escaped the slash in the test, I did escape the path in the Get implementation of whitelist itself:

    escapedIP := url.PathEscape(ip)
    path := fmt.Sprintf("%s/whitelist/%s", gid, escapedIP)

I'll continue looking into akshaykarle/terraform-provider-mongodbatlas#16 to see if there is something else I'm missing. Let me know if there is something else you may have noticed.