added some initial specs to test access control. Can connect and put content on the resources. webid
authorHenry Story <henry.story@bblfish.net>
Tue, 25 Oct 2011 16:03:57 +0200
branchwebid
changeset 100 09d4f2d2e8f3
parent 99 57279f08e70b
child 101 0e91da4bc405
added some initial specs to test access control. Can connect and put content on the resources.
keys/KEYSTORE.jks
src/main/scala/netty/ReadWriteWebNetty.scala
src/test/scala/ReadWriteWebSpecs.scala
src/test/scala/auth/CreateWebIDSpec.scala
src/test/scala/auth/SecureReadWriteWebSpec.scala
src/test/scala/auth/secure_specs.scala
src/test/scala/util/specs.scala
Binary file keys/KEYSTORE.jks has changed
--- a/src/main/scala/netty/ReadWriteWebNetty.scala	Sun Oct 23 21:39:07 2011 +0200
+++ b/src/main/scala/netty/ReadWriteWebNetty.scala	Tue Oct 25 16:03:57 2011 +0200
@@ -54,7 +54,6 @@
          baseURL.value.get,
          lang=rdfLanguage.value getOrElse RDFXML)(mode.value getOrElse ResourcesDontExistByDefault)
      
-//   val app = new ReadWriteWeb(filesystem, new RDFAuthZ(webCache,filesystem))
      val rww = new cycle.Plan  with cycle.ThreadPool with ServerErrorResponse with ReadWriteWeb[ReceivedMessage,HttpResponse]{
           val rm = filesystem
           def manif = manifest[ReceivedMessage]
--- a/src/test/scala/ReadWriteWebSpecs.scala	Sun Oct 23 21:39:07 2011 +0200
+++ b/src/test/scala/ReadWriteWebSpecs.scala	Tue Oct 25 16:03:57 2011 +0200
@@ -13,7 +13,7 @@
       PutRDFXMLSpec, PostRDFSpec,
       PutInvalidRDFXMLSpec, PostOnNonExistingResourceSpec,
       // sparql query
-      PostSelectSpec, PostConstructSpec, PostAskSpec, 
+      PostSelectSpec, PostConstructSpec, PostAskSpec,
       // sparql update
       PostInsertSpec,
       // delete content
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/test/scala/auth/CreateWebIDSpec.scala	Tue Oct 25 16:03:57 2011 +0200
@@ -0,0 +1,108 @@
+/*
+ * Copyright (c) 2011 Henry Story (bblfish.net)
+ * under the MIT licence defined at
+ *    http://www.opensource.org/licenses/mit-license.html
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
+ * this software and associated documentation files (the "Software"), to deal in the
+ * Software without restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so, subject to the
+ * following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
+ * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+package org.w3.readwriteweb.auth
+
+import org.w3.readwriteweb.utiltest._
+
+import dispatch._
+import org.w3.readwriteweb.TURTLE
+import java.security.KeyStore
+import java.io.{FileInputStream, File}
+import org.apache.http.conn.scheme.Scheme
+import javax.net.ssl.{X509TrustManager, TrustManager, TrustManagerFactory}
+import java.security.cert.X509Certificate
+import java.lang.String
+
+/**
+ * @author hjs
+ * @created: 23/10/2011
+ */
+
+object CreateWebIDSpec extends SecureFileSystemBased {
+  lazy val peopleDirUri = host / "wiki/people/"
+  lazy val webidProfileDir = peopleDirUri / "Lambda/"
+  lazy val webidProfile = webidProfileDir / "Joe"
+  lazy val joeProfileOnDisk = new File(root,"people/Lambda/Joe")
+
+  lazy val directory = new File(root, "people")
+  lazy val lambdaDir = new File(directory,"Lambda")
+
+{
+  val tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm())
+  val  sslContext = javax.net.ssl.SSLContext.getInstance("TLS");
+  sslContext.init(null, Array[TrustManager](new X509TrustManager {
+    def checkClientTrusted(chain: Array[X509Certificate], authType: String) {}
+    def checkServerTrusted(chain: Array[X509Certificate], authType: String) {}
+    def getAcceptedIssuers = Array[X509Certificate]()
+  }),null); // we are not trying to test our trust of localhost server
+  val sf = new org.apache.http.conn.ssl.SSLSocketFactory(sslContext)
+  val  scheme = new Scheme("https", sf, 443);
+  Http.client.getConnectionManager.getSchemeRegistry.register(scheme)
+}
+
+
+  val foaf = """
+       @prefix foaf: <http://xmlns.com/foaf/0.1/> .
+       @prefix : <#> .
+
+       <> a foaf:PersonalProfileDocument;
+          foaf:primaryTopic :me .
+
+       :jl a foaf:Person;
+           foaf:name "Joe Lambda"@en .
+  """
+
+  
+  "PUTing nothing on /people/" should {
+       "return a 201" in {
+         val httpCode = Http(peopleDirUri.secure.put(TURTLE, "") get_statusCode)
+         httpCode must_== 201
+       }
+       "create a directory on disk" in {
+         directory must be directory
+       }
+   }
+  
+  
+  "PUTing nothing on /people/Lambda/" should { // but should it really? Should it not create a resource too? Perhaps index.html?
+     "return a 201" in {
+       val httpCode = Http(webidProfileDir.secure.put(TURTLE, "") get_statusCode)
+       httpCode must_== 201
+     }
+     "create a directory on disk" in {
+       lambdaDir must be directory
+     }
+   }
+  
+  
+   "PUTing a WebID Profile on /people/Lambda/" should {
+     "return a 201" in {
+       val httpCode = Http( webidProfile.secure.put(TURTLE, foaf) get_statusCode )
+        httpCode must_== 201
+     }
+     "create a resource on disk" in {
+        joeProfileOnDisk must be file
+     }
+   }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/test/scala/auth/SecureReadWriteWebSpec.scala	Tue Oct 25 16:03:57 2011 +0200
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2011 Henry Story (bblfish.net)
+ * under the MIT licence defined at
+ *    http://www.opensource.org/licenses/mit-license.html
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
+ * this software and associated documentation files (the "Software"), to deal in the
+ * Software without restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so, subject to the
+ * following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
+ * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+package org.w3.readwriteweb.auth
+
+import org.specs.Specification
+
+/**
+ * @author hjs
+ * @created: 25/10/2011
+ */
+
+object SecureReadWriteWebSpec extends Specification {
+  "The Secure Read Write Web".isSpecifiedBy(
+     CreateWebIDSpec
+   )
+
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/test/scala/auth/secure_specs.scala	Tue Oct 25 16:03:57 2011 +0200
@@ -0,0 +1,86 @@
+/*
+ * Copyright (c) 2011 Henry Story (bblfish.net)
+ * under the MIT licence defined at
+ *    http://www.opensource.org/licenses/mit-license.html
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
+ * this software and associated documentation files (the "Software"), to deal in the
+ * Software without restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so, subject to the
+ * following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
+ * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+package org.w3.readwriteweb.auth
+
+import unfiltered.spec.netty.Started
+import org.specs.Specification
+import unfiltered.netty.{ReceivedMessage, ServerErrorResponse, cycle}
+import org.w3.readwriteweb.auth.RDFAuthZ
+import java.io.File
+import org.w3.readwriteweb._
+import grizzled.file.GrizzledFile._
+
+import org.specs.specification.BeforeAfter
+
+/**
+ * @author hjs
+ * @created: 24/10/2011
+ */
+
+
+trait SecureServed extends Started {
+  import org.w3.readwriteweb.netty._
+
+  def setup: (Https => Https)
+  lazy val server = setup( KeyAuth_Https(port) )
+
+}
+
+/**
+ * Netty resource managed with access control enabled
+ */
+trait SecureResourceManaged extends Specification with SecureServed {
+  import org.jboss.netty.handler.codec.http._
+
+  def resourceManager: ResourceManager
+
+  val webCache = new WebCache()
+
+  val rww = new cycle.Plan  with cycle.ThreadPool with ServerErrorResponse with ReadWriteWeb[ReceivedMessage,HttpResponse] {
+    val rm = resourceManager
+    def manif = manifest[ReceivedMessage]
+    override val authz = new RDFAuthZ[ReceivedMessage,HttpResponse](webCache,resourceManager)
+  }
+
+  def setup = { _.plan(rww) }
+
+}
+
+trait SecureFileSystemBased extends SecureResourceManaged {
+  lazy val mode: RWWMode = ResourcesDontExistByDefault
+
+  lazy val lang = TURTLE
+
+  lazy val baseURL = "/wiki"
+
+  lazy val root = new File(new File(System.getProperty("java.io.tmpdir")), "readwriteweb")
+
+  lazy val resourceManager = new Filesystem(root, baseURL, lang)(mode)
+
+  doBeforeSpec {
+    if (root.exists) root.deleteRecursively()
+    root.mkdir()
+  }
+
+}
--- a/src/test/scala/util/specs.scala	Sun Oct 23 21:39:07 2011 +0200
+++ b/src/test/scala/util/specs.scala	Tue Oct 25 16:03:57 2011 +0200
@@ -2,6 +2,7 @@
 
 import org.w3.readwriteweb._
 
+import auth.RDFAuthZ
 import org.specs._
 import dispatch._
 import java.io._
@@ -12,6 +13,7 @@
 import javax.servlet.http.{HttpServletRequest, HttpServletResponse}
 import unfiltered.filter.Planify
 import unfiltered.netty.{ReceivedMessage, ServerErrorResponse, cycle}
+import unfiltered.spec.netty.Started
 
 trait JettyResourceManaged extends Specification with unfiltered.spec.jetty.Served {
   
@@ -26,6 +28,9 @@
  
 }
 
+/**
+ * Netty Resource managed.
+ **/
 trait ResourceManaged extends Specification with unfiltered.spec.netty.Served {
   import org.jboss.netty.handler.codec.http._
 
@@ -34,7 +39,6 @@
   val rww = new cycle.Plan  with cycle.ThreadPool with ServerErrorResponse with ReadWriteWeb[ReceivedMessage,HttpResponse] {
     val rm = resourceManager
     def manif = manifest[ReceivedMessage]
-    //  override val authz = new RDFAuthZ[ReceivedMessage,HttpResponse](webCache,filesystem)
   }
 
   def setup = { _.plan(rww) }
@@ -42,23 +46,24 @@
 }
 
 
+
 trait FilesystemBased extends ResourceManaged {
-  
+
   lazy val mode: RWWMode = ResourcesDontExistByDefault
-  
+
   lazy val lang = RDFXML
-    
+
   lazy val baseURL = "/wiki"
-  
+
   lazy val root = new File(new File(System.getProperty("java.io.tmpdir")), "readwriteweb")
 
   lazy val resourceManager = new Filesystem(root, baseURL, lang)(mode)
-  
+
   doBeforeSpec {
     if (root.exists) root.deleteRecursively()
     root.mkdir()
   }
-  
+
 }
 
 trait SomeRDF extends SomeURI {