def permit_unsigned_manifests isok=true
# Set security model for the life of a test.
- Rails.configuration.Collections["BlobSigning"] = !isok
+ Rails.configuration.Collections.BlobSigning = !isok
end
def assert_signed_manifest manifest_text, label='', token: false
exp = tok[/\+A[[:xdigit:]]+@([[:xdigit:]]+)/, 1].to_i(16)
sig = Blob.sign_locator(
bare,
- key: Rails.configuration.Collections["BlobSigningKey"],
+ key: Rails.configuration.Collections.BlobSigningKey,
expire: exp,
api_token: token)[/\+A[^\+]*/, 0]
assert_includes tok, sig
token = api_client_authorizations(:active).send(token_method)
signed = Blob.sign_locator(
'acbd18db4cc2f85cedef654fccc4a4d8+3',
- key: Rails.configuration.Collections["BlobSigningKey"],
+ key: Rails.configuration.Collections.BlobSigningKey,
api_token: token)
authorize_with_token token
put :update, params: {
def request_capped_index(params={})
authorize_with :user1_with_load
coll1 = collections(:collection_1_of_201)
- Rails.configuration.API["MaxIndexDatabaseRead"] =
+ Rails.configuration.API.MaxIndexDatabaseRead =
yield(coll1.manifest_text.size)
get :index, params: {
select: %w(uuid manifest_text),
# Build a manifest with both signed and unsigned locators.
signing_opts = {
- key: Rails.configuration.Collections["BlobSigningKey"],
+ key: Rails.configuration.Collections.BlobSigningKey,
api_token: api_token(:active),
}
signed_locators = locators.collect do |x|
# TODO(twp): in phase 4, all locators will need to be signed, so
# this test should break and will need to be rewritten. Issue #2755.
signing_opts = {
- key: Rails.configuration.Collections["BlobSigningKey"],
+ key: Rails.configuration.Collections.BlobSigningKey,
api_token: api_token(:active),
ttl: 3600 # 1 hour
}
test "create fails with invalid signature" do
authorize_with :active
signing_opts = {
- key: Rails.configuration.Collections["BlobSigningKey"],
+ key: Rails.configuration.Collections.BlobSigningKey,
api_token: api_token(:active),
}
test "create fails with uuid of signed manifest" do
authorize_with :active
signing_opts = {
- key: Rails.configuration.Collections["BlobSigningKey"],
+ key: Rails.configuration.Collections.BlobSigningKey,
api_token: api_token(:active),
}
ea10d51bcf88862dbcc36eb292017dfd+45)
signing_opts = {
- key: Rails.configuration.Collections["BlobSigningKey"],
+ key: Rails.configuration.Collections.BlobSigningKey,
api_token: api_token(:active),
}
[1, 5, nil].each do |ask|
test "Set replication_desired=#{ask.inspect}" do
- Rails.configuration.Collections["DefaultReplication"] = 2
+ Rails.configuration.Collections.DefaultReplication = 2
authorize_with :active
put :update, params: {
id: collections(:replication_undesired_unconfirmed).uuid,
assert_equal 'value1', json_response['properties']['property1']
end
- test "create collection with properties" do
- authorize_with :active
- manifest_text = ". d41d8cd98f00b204e9800998ecf8427e 0:0:foo.txt\n"
- post :create, params: {
- collection: {
- manifest_text: manifest_text,
- portable_data_hash: "d30fe8ae534397864cb96c544f4cf102+47",
- properties: {'property_1' => 'value_1'}
+ [
+ {'property_1' => 'value_1'},
+ "{\"property_1\":\"value_1\"}",
+ ].each do |p|
+ test "create collection with valid properties param #{p.inspect}" do
+ authorize_with :active
+ manifest_text = ". d41d8cd98f00b204e9800998ecf8427e 0:0:foo.txt\n"
+ post :create, params: {
+ collection: {
+ manifest_text: manifest_text,
+ portable_data_hash: "d30fe8ae534397864cb96c544f4cf102+47",
+ properties: p
+ }
}
- }
- assert_response :success
- assert_not_nil json_response['uuid']
- assert_equal 'value_1', json_response['properties']['property_1']
+ assert_response :success
+ assert_not_nil json_response['uuid']
+ assert_equal Hash, json_response['properties'].class, 'Collection properties attribute should be of type hash'
+ assert_equal 'value_1', json_response['properties']['property_1']
+ end
+ end
+
+ [
+ false,
+ [],
+ 42,
+ 'some string',
+ '["json", "encoded", "array"]',
+ ].each do |p|
+ test "create collection with non-valid properties param #{p.inspect}" do
+ authorize_with :active
+ post :create, params: {
+ collection: {
+ name: "test collection with non-valid properties param '#{p.inspect}'",
+ manifest_text: '',
+ properties: p
+ }
+ }
+ assert_response 422
+ response_errors = json_response['errors']
+ assert_not_nil response_errors, 'Expected error in response'
+ end
end
[
end
end
- test 'get trashed collection with include_trash' do
- uuid = 'zzzzz-4zz18-mto52zx1s7sn3ih' # expired_collection
- authorize_with :active
- get :show, params: {
- id: uuid,
- include_trash: true,
- }
- assert_response 200
+ [true, false].each do |include_trash|
+ test "get trashed collection with include_trash=#{include_trash}" do
+ uuid = 'zzzzz-4zz18-mto52zx1s7sn3ih' # expired_collection
+ authorize_with :active
+ get :show, params: {
+ id: uuid,
+ include_trash: include_trash,
+ }
+ if include_trash
+ assert_response 200
+ else
+ assert_response 404
+ end
+ end
end
[:admin, :active].each do |user|
assert_response 200
c = Collection.find_by_uuid(uuid)
assert_operator c.trash_at, :<, db_current_time
- assert_equal c.delete_at, c.trash_at + Rails.configuration.Collections["BlobSigningTTL"]
+ assert_equal c.delete_at, c.trash_at + Rails.configuration.Collections.BlobSigningTTL
end
test 'delete long-trashed collection immediately using http DELETE verb' do
assert_response 200
c = Collection.find_by_uuid(uuid)
assert_operator c.trash_at, :<, db_current_time
- assert_operator c.delete_at, :>=, time_before_trashing + Rails.configuration.Collections["DefaultTrashLifetime"]
+ assert_operator c.delete_at, :>=, time_before_trashing + Rails.configuration.Collections.DefaultTrashLifetime
end
end
json_response['name']
end
+ test 'can get old version collection by PDH' do
+ authorize_with :active
+ get :show, params: {
+ id: collections(:collection_owned_by_active_past_version_1).portable_data_hash,
+ }
+ assert_response :success
+ assert_equal collections(:collection_owned_by_active_past_version_1).portable_data_hash,
+ json_response['portable_data_hash']
+ end
+
test 'version and current_version_uuid are ignored at creation time' do
permit_unsigned_manifests
authorize_with :active
end
test "update collection with versioning enabled" do
- Rails.configuration.Collections["CollectionVersioning"] = true
- Rails.configuration.Collections["PreserveVersionIfIdle"] = 1 # 1 second
+ Rails.configuration.Collections.CollectionVersioning = true
+ Rails.configuration.Collections.PreserveVersionIfIdle = 1 # 1 second
col = collections(:collection_owned_by_active)
assert_equal 2, col.version
token = api_client_authorizations(:active).v2token
signed = Blob.sign_locator(
'acbd18db4cc2f85cedef654fccc4a4d8+3',
- key: Rails.configuration.Collections["BlobSigningKey"],
+ key: Rails.configuration.Collections.BlobSigningKey,
api_token: token)
authorize_with_token token
put :update, params: {
assert_response :success
assert_equal 3, json_response['version']
end
+
+ test "delete collection with versioning enabled" do
+ Rails.configuration.Collections.CollectionVersioning = true
+ Rails.configuration.Collections.PreserveVersionIfIdle = 1 # 1 second
+
+ col = collections(:collection_owned_by_active)
+ assert_equal 2, col.version
+ assert col.modified_at < Time.now - 1.second
+
+ authorize_with(:active)
+ post :trash, params: {
+ id: col.uuid,
+ }
+ assert_response :success
+ assert_equal col.version, json_response['version'], 'Trashing a collection should not create a new version'
+ end
end