dlna: correct output for ContentDirectoryService#Browse with BrowseMetadata

We were marshalling the "cds object" instead of the "upnp object".

Fixes #3253  (I think)
This commit is contained in:
Dan Walters 2019-09-14 16:16:07 -05:00 committed by Nick Craig-Wood
parent fd4b25932c
commit 8c038326b9
2 changed files with 39 additions and 1 deletions

View file

@ -245,7 +245,15 @@ func (cds *contentDirectoryService) Handle(action string, argsXML []byte, r *htt
"UpdateID": cds.updateIDString(),
}, nil
case "BrowseMetadata":
result, err := xml.Marshal(obj)
node, err := cds.vfs.Stat(obj.Path)
if err != nil {
return nil, err
}
upnpObject, err := cds.cdsObjectToUpnpavObject(obj, node, host)
if err != nil {
return nil, err
}
result, err := xml.Marshal(upnpObject)
if err != nil {
return nil, err
}

View file

@ -7,6 +7,7 @@ import (
"net/http"
"net/url"
"os"
"strings"
"testing"
"github.com/rclone/rclone/vfs"
@ -91,3 +92,32 @@ func TestServeContent(t *testing.T) {
require.Equal(t, goldenContents, actualContents)
}
// Check that ContentDirectory#Browse returns appropriate metadata on the root container.
func TestContentDirectoryBrowseMetadata(t *testing.T) {
// Sample from: https://github.com/rclone/rclone/issues/3253#issuecomment-524317469
req, err := http.NewRequest("POST", testURL+"ctl", strings.NewReader(`
<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"
s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<s:Body>
<u:Browse xmlns:u="urn:schemas-upnp-org:service:ContentDirectory:1">
<ObjectID>0</ObjectID>
<BrowseFlag>BrowseMetadata</BrowseFlag>
<Filter>*</Filter>
<StartingIndex>0</StartingIndex>
<RequestedCount>0</RequestedCount>
<SortCriteria></SortCriteria>
</u:Browse>
</s:Body>
</s:Envelope>`))
require.NoError(t, err)
req.Header.Set("SOAPACTION", `"urn:schemas-upnp-org:service:ContentDirectory:1#Browse"`)
resp, err := http.DefaultClient.Do(req)
require.NoError(t, err)
assert.Equal(t, http.StatusOK, resp.StatusCode)
body, err := ioutil.ReadAll(resp.Body)
require.NoError(t, err)
require.Contains(t, string(body), "&lt;container ")
require.NotContains(t, string(body), "&lt;item ")
}