2016-02-27 14:42:08 -09:00
|
|
|
package api_test
|
2016-02-24 14:06:49 -09:00
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"encoding/xml"
|
2016-03-24 15:00:28 -08:00
|
|
|
"fmt"
|
2016-03-09 17:05:23 -09:00
|
|
|
"testing"
|
|
|
|
|
|
2017-04-01 05:47:14 -08:00
|
|
|
"github.com/cloudsonic/sonic-server/api/responses"
|
|
|
|
|
"github.com/cloudsonic/sonic-server/tests"
|
2016-02-24 14:06:49 -09:00
|
|
|
. "github.com/smartystreets/goconvey/convey"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestCheckParams(t *testing.T) {
|
2016-02-27 14:42:08 -09:00
|
|
|
tests.Init(t, false)
|
|
|
|
|
|
2016-02-24 14:24:06 -09:00
|
|
|
_, w := Get("/rest/ping.view", "TestCheckParams")
|
2016-02-24 14:06:49 -09:00
|
|
|
|
2016-02-25 07:14:16 -09:00
|
|
|
Convey("Subject: CheckParams\n", t, func() {
|
2016-02-24 14:06:49 -09:00
|
|
|
Convey("Status code should be 200", func() {
|
|
|
|
|
So(w.Code, ShouldEqual, 200)
|
|
|
|
|
})
|
|
|
|
|
Convey("The errorCode should be 10", func() {
|
|
|
|
|
So(w.Body.String(), ShouldContainSubstring, `error code="10" message=`)
|
|
|
|
|
})
|
|
|
|
|
Convey("The status should be 'fail'", func() {
|
|
|
|
|
v := responses.Subsonic{}
|
|
|
|
|
xml.Unmarshal(w.Body.Bytes(), &v)
|
|
|
|
|
So(v.Status, ShouldEqual, "fail")
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestAuthentication(t *testing.T) {
|
2016-03-09 17:05:23 -09:00
|
|
|
tests.Init(t, false)
|
2016-02-24 14:06:49 -09:00
|
|
|
|
2016-03-24 15:00:28 -08:00
|
|
|
Convey("Subject: Authentication", t, func() {
|
2016-03-09 17:05:23 -09:00
|
|
|
_, w := Get("/rest/ping.view?u=INVALID&p=INVALID&c=test&v=1.0.0", "TestAuthentication")
|
2016-02-24 14:06:49 -09:00
|
|
|
Convey("Status code should be 200", func() {
|
|
|
|
|
So(w.Code, ShouldEqual, 200)
|
|
|
|
|
})
|
|
|
|
|
Convey("The errorCode should be 10", func() {
|
|
|
|
|
So(w.Body.String(), ShouldContainSubstring, `error code="40" message=`)
|
|
|
|
|
})
|
|
|
|
|
Convey("The status should be 'fail'", func() {
|
|
|
|
|
v := responses.Subsonic{}
|
|
|
|
|
xml.Unmarshal(w.Body.Bytes(), &v)
|
|
|
|
|
So(v.Status, ShouldEqual, "fail")
|
|
|
|
|
})
|
|
|
|
|
})
|
2016-03-24 15:00:28 -08:00
|
|
|
Convey("Subject: Authentication Valid", t, func() {
|
2016-03-09 17:05:23 -09:00
|
|
|
_, w := Get("/rest/ping.view?u=deluan&p=wordpass&c=test&v=1.0.0", "TestAuthentication")
|
|
|
|
|
Convey("The status should be 'ok'", func() {
|
|
|
|
|
v := responses.Subsonic{}
|
|
|
|
|
xml.Unmarshal(w.Body.Bytes(), &v)
|
|
|
|
|
So(v.Status, ShouldEqual, "ok")
|
|
|
|
|
})
|
|
|
|
|
})
|
2016-03-24 15:00:28 -08:00
|
|
|
Convey("Subject: Password encoded", t, func() {
|
2016-03-09 17:05:23 -09:00
|
|
|
_, w := Get("/rest/ping.view?u=deluan&p=enc:776f726470617373&c=test&v=1.0.0", "TestAuthentication")
|
|
|
|
|
Convey("The status should be 'ok'", func() {
|
|
|
|
|
v := responses.Subsonic{}
|
|
|
|
|
xml.Unmarshal(w.Body.Bytes(), &v)
|
|
|
|
|
So(v.Status, ShouldEqual, "ok")
|
|
|
|
|
})
|
|
|
|
|
})
|
2016-03-24 15:00:28 -08:00
|
|
|
Convey("Subject: Token-based authentication", t, func() {
|
|
|
|
|
salt := "retnlmjetrymazgkt"
|
|
|
|
|
token := "23b342970e25c7928831c3317edd0b67"
|
|
|
|
|
_, w := Get(fmt.Sprintf("/rest/ping.view?u=deluan&s=%s&t=%s&c=test&v=1.0.0", salt, token), "TestAuthentication")
|
|
|
|
|
Convey("The status should be 'ok'", func() {
|
|
|
|
|
v := responses.Subsonic{}
|
|
|
|
|
xml.Unmarshal(w.Body.Bytes(), &v)
|
|
|
|
|
So(v.Status, ShouldEqual, "ok")
|
|
|
|
|
})
|
|
|
|
|
})
|
2016-02-24 14:06:49 -09:00
|
|
|
}
|