← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~jtv/gomaasapi/slash into lp:gomaasapi

 

Jeroen T. Vermeulen has proposed merging lp:~jtv/gomaasapi/slash into lp:gomaasapi.

Commit message:
Support slashes in filenames.

Requested reviews:
  MAAS Maintainers (maas-maintainers)

For more details, see:
https://code.launchpad.net/~jtv/gomaasapi/slash/+merge/152376

The test covers the full end-to-end functionality, minus just two things:

1. an actual MAAS server, and

2. query-escaping in the get/get_by_key operations, where slashes just aren't special.

So I'm confident that satisfying this one test provides all parts needed to get slashes in filenames working properly.  Now all we have to do is wait for reality to prove me wrong.


Jeroen
-- 
https://code.launchpad.net/~jtv/gomaasapi/slash/+merge/152376
Your team MAAS Maintainers is requested to review the proposed merge of lp:~jtv/gomaasapi/slash into lp:gomaasapi.
=== modified file 'testservice.go'
--- testservice.go	2013-03-05 08:58:34 +0000
+++ testservice.go	2013-03-08 11:06:29 +0000
@@ -166,7 +166,7 @@
 }
 
 func getFileURLRE(version string) *regexp.Regexp {
-	reString := fmt.Sprintf("^/api/%s/files/([^/]*)/$", regexp.QuoteMeta(version))
+	reString := fmt.Sprintf("^/api/%s/files/(.*)/$", regexp.QuoteMeta(version))
 	return regexp.MustCompile(reString)
 }
 

=== modified file 'testservice_test.go'
--- testservice_test.go	2013-03-05 09:10:02 +0000
+++ testservice_test.go	2013-03-08 11:06:29 +0000
@@ -451,3 +451,20 @@
 	c.Assert(err, IsNil)
 	c.Check(string(bytes), Equals, fileContent)
 }
+
+func (suite *TestMAASObjectSuite) TestFileNamesMayContainSlashes(c *C) {
+	const filename = "filename/with/slashes/in/it"
+	const fileContent = "file contents"
+	files := suite.TestMAASObject.GetSubObject("files")
+	params := url.Values{"filename": {filename}}
+	filesMap := map[string][]byte{"file": []byte(fileContent)}
+
+	_, err := files.CallPostFiles("add", params, filesMap)
+	c.Assert(err, IsNil)
+
+	file, err := files.GetSubObject(filename).Get()
+	c.Assert(err, IsNil)
+	field, err := file.GetField("content")
+	c.Assert(err, IsNil)
+	c.Check(field, Equals, base64.StdEncoding.EncodeToString([]byte(fileContent)))
+}