14287: Fix accepting JSON-encoded params in request body.
[arvados.git] / lib / controller / router / request_test.go
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 package router
6
7 import (
8         "bytes"
9         "net/http/httptest"
10
11         check "gopkg.in/check.v1"
12 )
13
14 func (s *RouterSuite) TestAttrsInBody(c *check.C) {
15         for _, body := range []string{
16                 `{"foo":"bar"}`,
17                 `{"model_name": {"foo":"bar"}}`,
18         } {
19                 c.Logf("body: %s", body)
20                 req := httptest.NewRequest("POST", "https://an.example/ctrl", bytes.NewBufferString(body))
21                 req.Header.Set("Content-Type", "application/json")
22                 params, err := s.rtr.loadRequestParams(req, "model_name")
23                 c.Assert(err, check.IsNil)
24                 c.Logf("params: %#v", params)
25                 c.Check(params, check.NotNil)
26                 c.Assert(params["attrs"], check.FitsTypeOf, map[string]interface{}{})
27                 c.Check(params["attrs"].(map[string]interface{})["foo"], check.Equals, "bar")
28         }
29 }