aa to new config
authorrautenberg <rautenberg@in-silico.ch>
Wed, 28 Mar 2012 10:54:05 +0000 (12:54 +0200)
committerrautenberg <rautenberg@in-silico.ch>
Wed, 28 Mar 2012 10:54:05 +0000 (12:54 +0200)
lib/authorization.rb
test/dataset.rb

index 470ecd8..33fa0a4 100644 (file)
@@ -1,6 +1,6 @@
 module OpenTox
-
-  AA ||= "https://opensso.in-silico.ch" #if not set in .opentox/conf/[environment].yaml
+  AA = $aa[:uri] if defined? $aa
+  AA ||= "https://opensso.in-silico.ch" #if not set in .opentox/conf/[application]/[test].rb
   #Module for Authorization and Authentication
   #@example Authentication
   #  require "opentox-client"
@@ -310,13 +310,13 @@ module OpenTox
     # @param [String] subjectid
     # @return [Boolean] true if access granted, else otherwise
     def self.authorized?(uri, request_method, subjectid)
-      if CONFIG[:authorization][:free_request].include?(request_method)
+      if $aa[:free_request].include?(request_method)
         #$logger.debug "authorized? >>true<< (request is free), method: #{request_method}, URI: #{uri}, subjectid: #{subjectid}"
         true
       elsif OpenTox::Authorization.free_uri?(uri, request_method)
         #$logger.debug "authorized? >>true<< (uris is free_uri), method: #{request_method}, URI: #{uri}, subjectid: #{subjectid}"
         true
-      elsif CONFIG[:authorization][:authenticate_request].include?(request_method)
+      elsif $aa[:authenticate_request].include?(request_method)
         ret = OpenTox::Authorization.is_token_valid(subjectid)
         $logger.debug "authorized? >>#{ret}<< (token is in/valid), method: #{request_method}, URI: #{uri}, subjectid: #{subjectid}" unless ret
         ret
@@ -324,7 +324,7 @@ module OpenTox
         ret = OpenTox::Authorization.is_token_valid(subjectid)
         $logger.debug "authorized? >>#{ret}<< (uris is authorize exception, token is in/valid), method: #{request_method}, URI: #{uri}, subjectid: #{subjectid}" unless ret
         ret
-      elsif CONFIG[:authorization][:authorize_request].include?(request_method)
+      elsif $aa[:authorize_request].include?(request_method)
         ret = OpenTox::Authorization.authorize(uri, request_method, subjectid)
         $logger.debug "authorized? >>#{ret}<< (uri (not) authorized), method: #{request_method}, URI: #{uri}, subjectid: #{subjectid}" unless ret
         ret
@@ -336,9 +336,9 @@ module OpenTox
 
     private
     def self.free_uri?(uri, request_method)
-      if CONFIG[:authorization][:free_uris]
-        CONFIG[:authorization][:free_uris].each do |request_methods,uris|
-          if request_methods and uris and request_methods.include?(request_method.to_sym)
+      if $aa[:free_uris]
+        $aa[:free_uris].each do |request_methods,uris|
+          if request_methods and uris and request_methods.include?(request_method.to_s)
             uris.each do |u|
               return true if u.match uri
             end
@@ -349,8 +349,8 @@ module OpenTox
     end
 
     def self.authorize_exception?(uri, request_method)
-      if CONFIG[:authorization][:authorize_exceptions]
-        CONFIG[:authorization][:authorize_exceptions].each do |request_methods,uris|
+      if $aa[:authorize_exceptions]
+        $aa[:authorize_exceptions].each do |request_methods,uris|
           if request_methods and uris and request_methods.include?(request_method.to_sym)
             uris.each do |u|
               return true if u.match uri
index e41db8e..b3190b8 100644 (file)
@@ -2,6 +2,11 @@ require 'test/unit'
 $LOAD_PATH << File.join(File.dirname(__FILE__),'..','lib')
 require File.join File.dirname(__FILE__),'..','lib','opentox-client.rb'
 DATASET = "http://ot-dev.in-silico.ch/dataset"
+AA ||= "https://opensso.in-silico.ch"
+AA_USER = "guest"
+AA_PASS = "guest"
+@@subjectid = OpenTox::Authorization.authenticate(AA_USER,AA_PASS)
+
 DATA_DIR = File.join(File.dirname(__FILE__),"data")
 # TODO: add subjectids
 
@@ -9,19 +14,20 @@ DATA_DIR = File.join(File.dirname(__FILE__),"data")
 class DatasetTest < Test::Unit::TestCase
 
   def test_all
-    datasets = OpenTox::Dataset.all DATASET
+    puts @@subjectid
+    datasets = OpenTox::Dataset.all(DATASET, @@subjectid)
     assert_equal OpenTox::Dataset, datasets.first.class
   end
 
   def test_create_empty
-    d = OpenTox::Dataset.create DATASET
+    d = OpenTox::Dataset.create(DATASET, @@subjectid)
     assert_equal OpenTox::Dataset, d.class
     assert_match /#{DATASET}/, d.uri.to_s
     d.delete
   end
 
   def test_create_from_file
-    d = OpenTox::Dataset.from_file DATASET, File.join(DATA_DIR,"EPAFHM.mini.csv")
+    d = OpenTox::Dataset.from_file DATASET, File.join(DATA_DIR,"EPAFHM.mini.csv"), @@subjectid
     assert_equal OpenTox::Dataset, d.class
     assert_equal d.uri, d[RDF::XSD.anyURI]
     assert_equal "EPAFHM.mini",  d.metadata[RDF::URI("http://purl.org/dc/elements/1.1/title")].first.to_s # DC.title is http://purl.org/dc/terms/title
@@ -33,7 +39,7 @@ class DatasetTest < Test::Unit::TestCase
   end
 
   def test_from_yaml
-    @dataset = OpenTox::Dataset.from_file DATASET, File.join(DATA_DIR,"hamster_carcinogenicity.yaml")
+    @dataset = OpenTox::Dataset.from_file DATASET, File.join(DATA_DIR,"hamster_carcinogenicity.yaml"), @@subjectid
     assert_equal OpenTox::Dataset, @dataset.class
     assert_equal "hamster_carcinogenicity", @dataset[RDF::URI("http://purl.org/dc/elements/1.1/title")]
     hamster_carc?
@@ -52,14 +58,14 @@ class DatasetTest < Test::Unit::TestCase
 =end
 
   def test_multicolumn_csv
-    @dataset = OpenTox::Dataset.from_file DATASET, "#{DATA_DIR}/multicolumn.csv"
+    @dataset = OpenTox::Dataset.from_file DATASET, "#{DATA_DIR}/multicolumn.csv", @@subjectid
     assert_equal 5, @dataset.features.size
     assert_equal 4, @dataset.compounds.size
     @dataset.delete
   end
 
   def test_from_csv
-    @dataset = OpenTox::Dataset.from_file DATASET, "#{DATA_DIR}/hamster_carcinogenicity.csv"
+    @dataset = OpenTox::Dataset.from_file DATASET, "#{DATA_DIR}/hamster_carcinogenicity.csv", @@subjectid
     assert_equal OpenTox::Dataset, @dataset.class
     hamster_carc?
     @dataset.delete