Token-based authentication implemented
This commit is contained in:
+14
-3
@@ -2,6 +2,7 @@ package api_test
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/deluan/gosonic/api/responses"
|
||||
@@ -32,7 +33,7 @@ func TestCheckParams(t *testing.T) {
|
||||
func TestAuthentication(t *testing.T) {
|
||||
tests.Init(t, false)
|
||||
|
||||
Convey("Subject: Authentication\n", t, func() {
|
||||
Convey("Subject: Authentication", t, func() {
|
||||
_, w := Get("/rest/ping.view?u=INVALID&p=INVALID&c=test&v=1.0.0", "TestAuthentication")
|
||||
Convey("Status code should be 200", func() {
|
||||
So(w.Code, ShouldEqual, 200)
|
||||
@@ -46,7 +47,7 @@ func TestAuthentication(t *testing.T) {
|
||||
So(v.Status, ShouldEqual, "fail")
|
||||
})
|
||||
})
|
||||
Convey("Subject: Authentication Valid\n", t, func() {
|
||||
Convey("Subject: Authentication Valid", t, func() {
|
||||
_, 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{}
|
||||
@@ -54,7 +55,7 @@ func TestAuthentication(t *testing.T) {
|
||||
So(v.Status, ShouldEqual, "ok")
|
||||
})
|
||||
})
|
||||
Convey("Subject: Password encoded\n", t, func() {
|
||||
Convey("Subject: Password encoded", t, func() {
|
||||
_, 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{}
|
||||
@@ -62,4 +63,14 @@ func TestAuthentication(t *testing.T) {
|
||||
So(v.Status, ShouldEqual, "ok")
|
||||
})
|
||||
})
|
||||
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")
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user