clarify Slug vs. UUID and fix event stream

refs CNVS-13987

what was called CanvasUuid was *not* generating UUIDs. it was generating
slugs. by default, its generate method only creates 4 character slugs.
these should obviously not be used as UUIDs. the misnomer already caused
a bug in EventStream where it used these slugs as UUIDs, causing
collisions. to fix:

 (1) rename canvas_uuid gem to canvas_slug, and rename it's primary
     class CanvasUuid to CanvasSlug
 (2) create new canvas_uuid gem, with class CanvasUUID, extracted from
     lib/uuid_singleton for actual UUID generation
 (3) fix event stream use CanvasUUID, rather than following the rename
     of CanvasUuid to CanvasSlug

test-plan:
 - have cassandra set up for audit logs
 - create an audit log entry (e.g. change a grade)
 - look at the generated audit log entry's id field; it should be a UUID
   value, not a 4 character slug

Change-Id: I19758fff4433cd6cb2e21219217dced19ee05c5a
Reviewed-on: https://gerrit.instructure.com/37506
Reviewed-by: Rob Orton <rob@instructure.com>
Tested-by: Jenkins <jenkins@instructure.com>
QA-Review: August Thornton <august@instructure.com>
QA-Review: Jeremy Putnam <jeremyp@instructure.com>
Product-Review: Brian Palmer <brianp@instructure.com>
This commit is contained in:
Jacob Fugal 2014-07-10 11:22:01 -06:00 committed by Brian Palmer
parent ba00b0154a
commit d9c6e2a0cd
55 changed files with 130 additions and 111 deletions

View File

@ -129,6 +129,7 @@ gem 'event_stream', :path => 'gems/event_stream'
gem 'canvas_mimetype_fu', :path => 'gems/canvas_mimetype_fu' gem 'canvas_mimetype_fu', :path => 'gems/canvas_mimetype_fu'
gem 'canvas_quiz_statistics', :path => 'gems/canvas_quiz_statistics' gem 'canvas_quiz_statistics', :path => 'gems/canvas_quiz_statistics'
gem 'canvas_sanitize', :path => 'gems/canvas_sanitize' gem 'canvas_sanitize', :path => 'gems/canvas_sanitize'
gem 'canvas_slug', :path => 'gems/canvas_slug'
gem 'canvas_sort', :path => 'gems/canvas_sort' gem 'canvas_sort', :path => 'gems/canvas_sort'
gem 'canvas_statsd', :path => 'gems/canvas_statsd' gem 'canvas_statsd', :path => 'gems/canvas_statsd'
gem 'canvas_stringex', :path => 'gems/canvas_stringex' gem 'canvas_stringex', :path => 'gems/canvas_stringex'

View File

@ -148,7 +148,7 @@ class UsersController < ApplicationController
:service => 'google_docs', :service => 'google_docs',
:token => request_token.token, :token => request_token.token,
:secret => request_token.secret, :secret => request_token.secret,
:user_secret => CanvasUuid::Uuid.generate(nil, 16), :user_secret => CanvasSlug.generate(nil, 16),
:return_url => return_to_url, :return_url => return_to_url,
:user => @real_current_user || @current_user, :user => @real_current_user || @current_user,
:original_host_with_port => request.host_with_port :original_host_with_port => request.host_with_port
@ -186,7 +186,7 @@ class UsersController < ApplicationController
elsif params[:service] == "facebook" elsif params[:service] == "facebook"
oauth_request = OauthRequest.create( oauth_request = OauthRequest.create(
:service => 'facebook', :service => 'facebook',
:secret => CanvasUuid::Uuid.generate("fb", 10), :secret => CanvasSlug.generate("fb", 10),
:return_url => return_to_url, :return_url => return_to_url,
:user => @current_user, :user => @current_user,
:original_host_with_port => request.host_with_port :original_host_with_port => request.host_with_port

View File

@ -24,7 +24,7 @@ class RequestContextGenerator
def call(env) def call(env)
# This is a crummy way to plumb this data through to the logger # This is a crummy way to plumb this data through to the logger
request_id = UUIDSingleton.instance.generate request_id = CanvasUUID.generate
session_id = (env['rack.session.options'] || {})[:id] session_id = (env['rack.session.options'] || {})[:id]
Thread.current[:context] = { Thread.current[:context] = {
:request_id => request_id, :request_id => request_id,

View File

@ -71,7 +71,7 @@ class AccessToken < ActiveRecord::Base
def generate_token(overwrite=false) def generate_token(overwrite=false)
if overwrite || !self.crypted_token if overwrite || !self.crypted_token
self.token = CanvasUuid::Uuid.generate(nil, TOKEN_SIZE) self.token = CanvasSlug.generate(nil, TOKEN_SIZE)
end end
end end

View File

@ -320,7 +320,7 @@ class Account < ActiveRecord::Base
end end
def ensure_defaults def ensure_defaults
self.uuid ||= CanvasUuid::Uuid.generate_securish_uuid self.uuid ||= CanvasSlug.generate_securish_uuid
self.lti_guid ||= self.uuid if self.respond_to?(:lti_guid) self.lti_guid ||= self.uuid if self.respond_to?(:lti_guid)
end end

View File

@ -43,7 +43,7 @@ class AssessmentRequest < ActiveRecord::Base
has_a_broadcast_policy has_a_broadcast_policy
def infer_uuid def infer_uuid
self.uuid ||= CanvasUuid::Uuid.generate_securish_uuid self.uuid ||= CanvasSlug.generate_securish_uuid
end end
protected :infer_uuid protected :infer_uuid

View File

@ -942,7 +942,7 @@ class Assignment < ActiveRecord::Base
:media_comment_id => (opts.delete :media_comment_id), :media_comment_id => (opts.delete :media_comment_id),
:media_comment_type => (opts.delete :media_comment_type), :media_comment_type => (opts.delete :media_comment_type),
} }
comment[:group_comment_id] = CanvasUuid::Uuid.generate_securish_uuid if group_comment && group comment[:group_comment_id] = CanvasSlug.generate_securish_uuid if group_comment && group
submissions = [] submissions = []
find_or_create_submissions(students) do |submission| find_or_create_submissions(students) do |submission|
submission_updated = false submission_updated = false
@ -1051,7 +1051,7 @@ class Assignment < ActiveRecord::Base
res = find_or_create_submissions(students) do |s| res = find_or_create_submissions(students) do |s|
s.group = group s.group = group
s.save! if s.changed? s.save! if s.changed?
opts[:group_comment_id] = CanvasUuid::Uuid.generate_securish_uuid if group opts[:group_comment_id] = CanvasSlug.generate_securish_uuid if group
s.add_comment(opts) s.add_comment(opts)
# this is lame, SubmissionComment updates the submission directly in the db # this is lame, SubmissionComment updates the submission directly in the db
# in an after_save, and of course Rails doesn't preload the reverse association # in an after_save, and of course Rails doesn't preload the reverse association
@ -1124,7 +1124,7 @@ class Assignment < ActiveRecord::Base
context_module_action(homework.student, homework.workflow_state.to_sym) context_module_action(homework.student, homework.workflow_state.to_sym)
if comment && (group_comment || homework == primary_homework) if comment && (group_comment || homework == primary_homework)
hash = {:comment => comment, :author => original_student} hash = {:comment => comment, :author => original_student}
hash[:group_comment_id] = CanvasUuid::Uuid.generate_securish_uuid if group_comment && group hash[:group_comment_id] = CanvasSlug.generate_securish_uuid if group_comment && group
homework.add_comment(hash) homework.add_comment(hash)
end end
end end
@ -1377,7 +1377,7 @@ class Assignment < ActiveRecord::Base
attachments: attachments, attachments: attachments,
} }
group, students = group_students(user) group, students = group_students(user)
comment[:group_comment_id] = CanvasUuid::Uuid.generate_securish_uuid if group comment[:group_comment_id] = CanvasSlug.generate_securish_uuid if group
find_or_create_submissions(students).map do |submission| find_or_create_submissions(students).map do |submission|
submission.add_comment(comment) submission.add_comment(comment)
end end

View File

@ -737,7 +737,7 @@ class Attachment < ActiveRecord::Base
before_save :assign_uuid before_save :assign_uuid
def assign_uuid def assign_uuid
self.uuid ||= CanvasUuid::Uuid.generate_securish_uuid self.uuid ||= CanvasSlug.generate_securish_uuid
end end
protected :assign_uuid protected :assign_uuid

View File

@ -278,7 +278,7 @@ class Collaboration < ActiveRecord::Base
# #
# Returns a UUID string. # Returns a UUID string.
def assign_uuid def assign_uuid
self.uuid ||= CanvasUuid::Uuid.generate_securish_uuid self.uuid ||= CanvasSlug.generate_securish_uuid
end end
protected :assign_uuid protected :assign_uuid

View File

@ -206,9 +206,9 @@ class CommunicationChannel < ActiveRecord::Base
def set_confirmation_code(reset=false) def set_confirmation_code(reset=false)
self.confirmation_code = nil if reset self.confirmation_code = nil if reset
if self.path_type == TYPE_EMAIL or self.path_type.nil? if self.path_type == TYPE_EMAIL or self.path_type.nil?
self.confirmation_code ||= CanvasUuid::Uuid.generate(nil, 25) self.confirmation_code ||= CanvasSlug.generate(nil, 25)
else else
self.confirmation_code ||= CanvasUuid::Uuid.generate self.confirmation_code ||= CanvasSlug.generate
end end
true true
end end

View File

@ -954,7 +954,7 @@ class Course < ActiveRecord::Base
end end
def self.create_unique(uuid=nil, account_id=nil, root_account_id=nil) def self.create_unique(uuid=nil, account_id=nil, root_account_id=nil)
uuid ||= CanvasUuid::Uuid.generate_securish_uuid uuid ||= CanvasSlug.generate_securish_uuid
course = find_or_initialize_by_uuid(uuid) course = find_or_initialize_by_uuid(uuid)
course = Course.new if course.deleted? course = Course.new if course.deleted?
course.name = self.default_name if course.new_record? course.name = self.default_name if course.new_record?
@ -999,7 +999,7 @@ class Course < ActiveRecord::Base
end end
def assign_uuid def assign_uuid
self.uuid ||= CanvasUuid::Uuid.generate_securish_uuid self.uuid ||= CanvasSlug.generate_securish_uuid
end end
protected :assign_uuid protected :assign_uuid

View File

@ -38,7 +38,7 @@ class DeveloperKey < ActiveRecord::Base
end end
def generate_api_key(overwrite=false) def generate_api_key(overwrite=false)
self.api_key = CanvasUuid::Uuid.generate(nil, 64) if overwrite || !self.api_key self.api_key = CanvasSlug.generate(nil, 64) if overwrite || !self.api_key
end end
def self.default def self.default

View File

@ -927,13 +927,13 @@ class Enrollment < ActiveRecord::Base
def assign_uuid def assign_uuid
# DON'T use ||=, because that will cause an immediate save to the db if it # DON'T use ||=, because that will cause an immediate save to the db if it
# doesn't already exist # doesn't already exist
self.uuid = CanvasUuid::Uuid.generate_securish_uuid if !read_attribute(:uuid) self.uuid = CanvasSlug.generate_securish_uuid if !read_attribute(:uuid)
end end
protected :assign_uuid protected :assign_uuid
def uuid def uuid
if !read_attribute(:uuid) if !read_attribute(:uuid)
self.update_attribute(:uuid, CanvasUuid::Uuid.generate_securish_uuid) self.update_attribute(:uuid, CanvasSlug.generate_securish_uuid)
end end
read_attribute(:uuid) read_attribute(:uuid)
end end

View File

@ -47,7 +47,7 @@ class Eportfolio < ActiveRecord::Base
before_create :assign_uuid before_create :assign_uuid
def assign_uuid def assign_uuid
self.uuid ||= CanvasUuid::Uuid.generate_securish_uuid self.uuid ||= CanvasSlug.generate_securish_uuid
end end
protected :assign_uuid protected :assign_uuid

View File

@ -327,7 +327,7 @@ class Group < ActiveRecord::Base
:updated_at => current_time :updated_at => current_time
}.merge(options) }.merge(options)
GroupMembership.bulk_insert(users.map{ |user| GroupMembership.bulk_insert(users.map{ |user|
options.merge({:user_id => user.id, :uuid => CanvasUuid::Uuid.generate_securish_uuid}) options.merge({:user_id => user.id, :uuid => CanvasSlug.generate_securish_uuid})
}) })
end end
@ -381,8 +381,8 @@ class Group < ActiveRecord::Base
end end
def ensure_defaults def ensure_defaults
self.name ||= CanvasUuid::Uuid.generate_securish_uuid self.name ||= CanvasSlug.generate_securish_uuid
self.uuid ||= CanvasUuid::Uuid.generate_securish_uuid self.uuid ||= CanvasSlug.generate_securish_uuid
self.group_category ||= GroupCategory.student_organized_for(self.context) self.group_category ||= GroupCategory.student_organized_for(self.context)
self.join_level ||= 'invitation_only' self.join_level ||= 'invitation_only'
self.is_public ||= false self.is_public ||= false

View File

@ -93,7 +93,7 @@ class GroupMembership < ActiveRecord::Base
end end
def assign_uuid def assign_uuid
self.uuid ||= CanvasUuid::Uuid.generate_securish_uuid self.uuid ||= CanvasSlug.generate_securish_uuid
end end
protected :assign_uuid protected :assign_uuid

View File

@ -167,7 +167,7 @@ class Pseudonym < ActiveRecord::Base
if !self.persistence_token || self.persistence_token == '' if !self.persistence_token || self.persistence_token == ''
# Some pseudonyms can end up without a persistence token if they were created # Some pseudonyms can end up without a persistence token if they were created
# using the SIS, for example. # using the SIS, for example.
self.persistence_token = CanvasUuid::Uuid.generate('pseudo', 15) self.persistence_token = CanvasSlug.generate('pseudo', 15)
self.save self.save
end end

View File

@ -87,7 +87,7 @@ class ReportSnapshot < ActiveRecord::Base
installation_uuid = Setting.get("installation_uuid", "") installation_uuid = Setting.get("installation_uuid", "")
if installation_uuid == "" if installation_uuid == ""
installation_uuid = CanvasUuid::Uuid.generate_securish_uuid installation_uuid = CanvasSlug.generate_securish_uuid
Setting.set("installation_uuid", installation_uuid) Setting.set("installation_uuid", installation_uuid)
end end

View File

@ -47,7 +47,7 @@ class Thumbnail < ActiveRecord::Base
before_save :assign_uuid before_save :assign_uuid
def assign_uuid def assign_uuid
self.uuid ||= CanvasUuid::Uuid.generate_securish_uuid self.uuid ||= CanvasSlug.generate_securish_uuid
end end
protected :assign_uuid protected :assign_uuid
end end

View File

@ -558,7 +558,7 @@ class User < ActiveRecord::Base
def assign_uuid def assign_uuid
# DON'T use ||=, because that will cause an immediate save to the db if it # DON'T use ||=, because that will cause an immediate save to the db if it
# doesn't already exist # doesn't already exist
self.uuid = CanvasUuid::Uuid.generate_securish_uuid if !read_attribute(:uuid) self.uuid = CanvasSlug.generate_securish_uuid if !read_attribute(:uuid)
end end
protected :assign_uuid protected :assign_uuid
@ -1433,7 +1433,7 @@ class User < ActiveRecord::Base
def uuid def uuid
if !read_attribute(:uuid) if !read_attribute(:uuid)
self.update_attribute(:uuid, CanvasUuid::Uuid.generate_securish_uuid) self.update_attribute(:uuid, CanvasSlug.generate_securish_uuid)
end end
read_attribute(:uuid) read_attribute(:uuid)
end end

View File

@ -171,7 +171,7 @@ class WebConference < ActiveRecord::Base
end end
def assign_uuid def assign_uuid
self.uuid ||= CanvasUuid::Uuid.generate_securish_uuid self.uuid ||= CanvasSlug.generate_securish_uuid
end end
protected :assign_uuid protected :assign_uuid

View File

@ -3,7 +3,7 @@
<p><%= t 'notices.uploading_progress_info', 'Uploading and processing your zip file, if there are a lot of files in the zip file or it is very large, this may take a while.' %></p> <p><%= t 'notices.uploading_progress_info', 'Uploading and processing your zip file, if there are a lot of files in the zip file or it is very large, this may take a while.' %></p>
</div> </div>
<%= form_for((@zfi || ZipFileImport.new), :url => context_url(@context, :context_zip_file_imports_url), :html => { :id => "zip_file_import_form", :multipart => true }) do |form| %> <%= form_for((@zfi || ZipFileImport.new), :url => context_url(@context, :context_zip_file_imports_url), :html => { :id => "zip_file_import_form", :multipart => true }) do |form| %>
<input type="hidden" name="batch_id" value="<%= CanvasUuid::Uuid.generate(@current_user.asset_string, 10) %>" id="zip_import_batch_id"/> <input type="hidden" name="batch_id" value="<%= CanvasSlug.generate(@current_user.asset_string, 10) %>" id="zip_import_batch_id"/>
<%= form.error_messages %> <%= form.error_messages %>
<div> <div>
<input type="file" name="zip_file" id="zip_file"/><br/> <input type="file" name="zip_file" id="zip_file"/><br/>

View File

@ -6,7 +6,7 @@ class AddThumbnailUuid < ActiveRecord::Migration
add_index :thumbnails, [:id, :uuid] add_index :thumbnails, [:id, :uuid]
Thumbnail.find_each do |t| Thumbnail.find_each do |t|
t.uuid ||= CanvasUuid::Uuid.generate_securish_uuid t.uuid ||= CanvasSlug.generate_securish_uuid
t.save t.save
end end
end end

View File

@ -2,7 +2,7 @@ source 'https://rubygems.org'
gem 'canvas_sort', :path => '../canvas_sort' gem 'canvas_sort', :path => '../canvas_sort'
gem 'canvas_http', :path => '../canvas_http' gem 'canvas_http', :path => '../canvas_http'
gem 'canvas_uuid', :path => '../canvas_uuid' gem 'canvas_slug', :path => '../canvas_slug'
gem 'multipart', :path => '../multipart' gem 'multipart', :path => '../multipart'
gemspec gemspec

View File

@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
spec.add_dependency "canvas_http" spec.add_dependency "canvas_http"
spec.add_dependency "canvas_sort" spec.add_dependency "canvas_sort"
spec.add_dependency "multipart" spec.add_dependency "multipart"
spec.add_dependency "canvas_uuid" spec.add_dependency "canvas_slug"
spec.add_development_dependency "bundler", "~> 1.5" spec.add_development_dependency "bundler", "~> 1.5"
spec.add_development_dependency "rake" spec.add_development_dependency "rake"

3
gems/canvas_slug/Gemfile Normal file
View File

@ -0,0 +1,3 @@
source 'https://rubygems.org'
gemspec

View File

@ -0,0 +1 @@
require "bundler/gem_tasks"

View File

@ -0,0 +1,20 @@
# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
Gem::Specification.new do |spec|
spec.name = "canvas_slug"
spec.version = "0.0.1"
spec.authors = ["Raphael Weiner"]
spec.email = ["rweiner@pivotallabs.com"]
spec.summary = %q{Canvas Slug generation}
spec.files = Dir.glob("{lib,test}/**/*") + %w(Rakefile)
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ["lib"]
spec.add_development_dependency "bundler", "~> 1.5"
spec.add_development_dependency "rake"
end

View File

@ -16,8 +16,9 @@
# with this program. If not, see <http://www.gnu.org/licenses/>. # with this program. If not, see <http://www.gnu.org/licenses/>.
# #
module CanvasUuid require "securerandom"
class Uuid
class CanvasSlug
class << self class << self
CHARS = ('0'..'9').to_a + ('a'..'z').to_a + ('A'..'Z').to_a CHARS = ('0'..'9').to_a + ('a'..'z').to_a + ('A'..'Z').to_a
@ -32,5 +33,10 @@ module CanvasUuid
slug slug
end end
end end
end end
# TODO: stub until other references to CanvasUuid outside core canvas-lms
# are replaced with CanvasSlug. remove when those are updated.
module CanvasUuid
Uuid = CanvasSlug
end end

View File

@ -6,8 +6,8 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
Gem::Specification.new do |spec| Gem::Specification.new do |spec|
spec.name = "canvas_uuid" spec.name = "canvas_uuid"
spec.version = "0.0.1" spec.version = "0.0.1"
spec.authors = ["Raphael Weiner"] spec.authors = ["Jacob Fugal"]
spec.email = ["rweiner@pivotallabs.com"] spec.email = ["jacob@instructure.com"]
spec.summary = %q{Canvas UUID generation} spec.summary = %q{Canvas UUID generation}
spec.files = Dir.glob("{lib,test}/**/*") + %w(Rakefile) spec.files = Dir.glob("{lib,test}/**/*") + %w(Rakefile)
@ -17,4 +17,6 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "bundler", "~> 1.5" spec.add_development_dependency "bundler", "~> 1.5"
spec.add_development_dependency "rake" spec.add_development_dependency "rake"
spec.add_dependency "uuid", "2.3.2"
end end

View File

@ -16,8 +16,20 @@
# with this program. If not, see <http://www.gnu.org/licenses/>. # with this program. If not, see <http://www.gnu.org/licenses/>.
# #
require "securerandom" require "uuid"
module CanvasUuid # Creating a testable Singleton for UUID
require "canvas_uuid/uuid" class CanvasUUID < ::UUID
def self.instance
@@uuid_singleton ||= new
end
def self.generate
instance.generate
end
end end
# Disable the UUID lib's state file thing. Across all processes, defaults to
# /var/tmp/ruby-uuid? *boggle*. We could do a tempfile thing, but this lib
# doesn't clean up after itself.
CanvasUUID.state_file = false

View File

@ -35,7 +35,7 @@ class EventStream::Record < Struct.new(:attributes)
attributes['request_id'] = request_id.to_s attributes['request_id'] = request_id.to_s
end end
attributes['id'] ||= CanvasUuid::Uuid.generate attributes['id'] ||= CanvasUUID.generate
attributes['created_at'] ||= Time.zone.now attributes['created_at'] ||= Time.zone.now
attributes['created_at'] = Time.zone.at(attributes['created_at'].to_i) attributes['created_at'] = Time.zone.at(attributes['created_at'].to_i)
attributes['event_type'] ||= self.class.name.gsub("::#{self.class.name.demodulize}", '').demodulize.underscore attributes['event_type'] ||= self.class.name.gsub("::#{self.class.name.demodulize}", '').demodulize.underscore

View File

@ -26,7 +26,7 @@ describe EventStream::Failure do
end end
before do before do
@request_id = CanvasUuid::Uuid.generate @request_id = CanvasUUID.generate
@event = EventRecord.new( @event = EventRecord.new(
'attribute1' => 'value1', 'attribute1' => 'value1',
'attribute2' => 'value2', 'attribute2' => 'value2',
@ -43,9 +43,9 @@ describe EventStream::Failure do
it "allows overrided default values" do it "allows overrided default values" do
attributes = { attributes = {
'id' => CanvasUuid::Uuid.generate, 'id' => CanvasUUID.generate,
'event_type' => 'other_type', 'event_type' => 'other_type',
'request_id' => CanvasUuid::Uuid.generate, 'request_id' => CanvasUUID.generate,
'created_at' => Time.zone.now 'created_at' => Time.zone.now
} }
event = EventRecord.new(attributes) event = EventRecord.new(attributes)
@ -68,7 +68,7 @@ describe EventStream::Failure do
request_id = 42 request_id = 42
attributes = { attributes = {
'id' => CanvasUuid::Uuid.generate, 'id' => CanvasUUID.generate,
'event_type' => 'other_type', 'event_type' => 'other_type',
'request_id' => request_id, 'request_id' => request_id,
'created_at' => Time.zone.now 'created_at' => Time.zone.now

View File

@ -2,4 +2,4 @@ source 'https://rubygems.org'
gemspec gemspec
gem "canvas_uuid", path: "../canvas_uuid" gem "canvas_slug", path: "../canvas_slug"

View File

@ -8,7 +8,7 @@
### NOW: ### NOW:
## Everything wrong is due to keith@oreilly.com ## Everything wrong is due to keith@oreilly.com
require "canvas_uuid" require "canvas_slug"
require "mime/types" require "mime/types"
require "net/http" require "net/http"
require "cgi" require "cgi"

View File

@ -1,6 +1,6 @@
module Multipart module Multipart
class Post class Post
BOUNDARY = CanvasUuid::Uuid.generate('canvas-rules', 15) BOUNDARY = ::CanvasSlug.generate('canvas-rules', 15)
HEADER = {"Content-type" => "multipart/form-data, boundary=" + BOUNDARY} HEADER = {"Content-type" => "multipart/form-data, boundary=" + BOUNDARY}
def prepare_query (params, field_priority=[]) def prepare_query (params, field_priority=[])

View File

@ -15,7 +15,7 @@ Gem::Specification.new do |spec|
spec.require_paths = ["lib"] spec.require_paths = ["lib"]
spec.add_dependency "mime-types", "1.17.2" spec.add_dependency "mime-types", "1.17.2"
spec.add_dependency "canvas_uuid" spec.add_dependency "canvas_slug"
spec.add_development_dependency "bundler", "~> 1.5" spec.add_development_dependency "bundler", "~> 1.5"
spec.add_development_dependency "rake" spec.add_development_dependency "rake"

View File

@ -2,7 +2,7 @@ module UserContent
def self.escape(str, current_host = nil) def self.escape(str, current_host = nil)
html = Nokogiri::HTML::DocumentFragment.parse(str) html = Nokogiri::HTML::DocumentFragment.parse(str)
find_user_content(html) do |obj, uc| find_user_content(html) do |obj, uc|
uuid = UUIDSingleton.instance.generate uuid = CanvasUUID.generate
child = Nokogiri::XML::Node.new("iframe", html) child = Nokogiri::XML::Node.new("iframe", html)
child['class'] = 'user_content_iframe' child['class'] = 'user_content_iframe'
child['name'] = uuid child['name'] = uuid

View File

@ -1,30 +1,4 @@
# # TODO: stub file until other references to UUIDSingleton outside core
# Copyright (C) 2011 Instructure, Inc. # canvas-lms are replaced with CanvasUUID. remove when those are updated.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Creating a testable Singleton for UUID
class UUIDSingleton < UUID
def self.instance
@@uuid_singleton ||= new
end
end
# Disable the UUID lib's state file thing. Across all processes, defaults to
# /var/tmp/ruby-uuid? *boggle*. We could do a tempfile thing, but this lib
# doesn't clean up after itself.
UUIDSingleton.state_file = false
UUIDSingleton = CanvasUUID

View File

@ -68,9 +68,9 @@ class ZipExtractor
alias :dirname :make_safe_haven alias :dirname :make_safe_haven
def safe_haven_name def safe_haven_name
dirname = "/tmp/#{CanvasUuid::Uuid.generate}" dirname = "/tmp/#{CanvasSlug.generate}"
while File.exist?(dirname) while File.exist?(dirname)
dirname = "/tmp/#{CanvasUuid::Uuid.generate}" dirname = "/tmp/#{CanvasSlug.generate}"
end end
dirname dirname
end end

View File

@ -41,7 +41,7 @@ describe "AuthenticationAudit API", type: :request do
before do before do
Setting.set('enable_page_views', 'cassandra') Setting.set('enable_page_views', 'cassandra')
@request_id = UUIDSingleton.instance.generate @request_id = CanvasUUID.generate
RequestContextGenerator.stubs( :request_id => @request_id ) RequestContextGenerator.stubs( :request_id => @request_id )
@viewing_user = site_admin_user(user: user_with_pseudonym(account: Account.site_admin)) @viewing_user = site_admin_user(user: user_with_pseudonym(account: Account.site_admin))
@ -267,7 +267,7 @@ describe "AuthenticationAudit API", type: :request do
before do before do
@event2 = @pseudonym.shard.activate do @event2 = @pseudonym.shard.activate do
record = Auditors::Authentication::Record.new( record = Auditors::Authentication::Record.new(
'id' => UUIDSingleton.instance.generate, 'id' => CanvasUUID.generate,
'created_at' => 1.day.ago, 'created_at' => 1.day.ago,
'pseudonym' => @pseudonym, 'pseudonym' => @pseudonym,
'event_type' => 'logout') 'event_type' => 'logout')

View File

@ -40,7 +40,7 @@ describe "CourseAudit API", type: :request do
include_examples "cassandra audit logs" include_examples "cassandra audit logs"
before do before do
@request_id = UUIDSingleton.instance.generate @request_id = CanvasUUID.generate
RequestContextGenerator.stubs( :request_id => @request_id ) RequestContextGenerator.stubs( :request_id => @request_id )
@domain_root_account = Account.default @domain_root_account = Account.default

View File

@ -42,7 +42,7 @@ describe "GradeChangeAudit API", type: :request do
include_examples "cassandra audit logs" include_examples "cassandra audit logs"
before do before do
@request_id = UUIDSingleton.instance.generate @request_id = CanvasUUID.generate
RequestContextGenerator.stubs( :request_id => @request_id ) RequestContextGenerator.stubs( :request_id => @request_id )
@domain_root_account = Account.default @domain_root_account = Account.default

View File

@ -146,7 +146,7 @@ describe EportfolioEntriesController do
eportfolio_category eportfolio_category
eportfolio_entry(@category) eportfolio_entry(@category)
begin begin
get 'attachment', :eportfolio_id => @portfolio.id, :entry_id => @entry.id, :attachment_id => UUIDSingleton.instance.generate get 'attachment', :eportfolio_id => @portfolio.id, :entry_id => @entry.id, :attachment_id => CanvasUUID.generate
rescue => e rescue => e
e.to_s.should eql("Not Found") e.to_s.should eql("Not Found")
end end

View File

@ -66,7 +66,7 @@ describe UsersController do
Facebook::Connection.config = Proc.new do Facebook::Connection.config = Proc.new do
{} {}
end end
CanvasUuid::Uuid.stubs(:generate).returns("some_uuid") CanvasSlug.stubs(:generate).returns("some_uuid")
user_with_pseudonym user_with_pseudonym
user_session(@user) user_session(@user)

View File

@ -23,7 +23,7 @@ end
def valid_page_view_attributes def valid_page_view_attributes
{ {
:url => "http://www.example.com/courses/1", :url => "http://www.example.com/courses/1",
:request_id => UUIDSingleton.instance.generate, :request_id => CanvasUUID.generate,
:user => @user || user :user => @user || user
} }
end end

View File

@ -24,10 +24,10 @@ end
# Re-generate these because I need a Unique ID # Re-generate these because I need a Unique ID
def valid_pseudonym_attributes def valid_pseudonym_attributes
{ {
:unique_id => "#{UUIDSingleton.instance.generate}@example.com", :unique_id => "#{CanvasUUID.generate}@example.com",
:password => "password", :password => "password",
:password_confirmation => "password", :password_confirmation => "password",
:persistence_token => "pt_#{UUIDSingleton.instance.generate}", :persistence_token => "pt_#{CanvasUUID.generate}",
:perishable_token => "value for perishable_token", :perishable_token => "value for perishable_token",
:login_count => 1, :login_count => 1,
:failed_login_count => 0, :failed_login_count => 0,

View File

@ -40,7 +40,7 @@ describe Api::V1::CourseEvent do
before do before do
pending("needs auditors cassandra keyspace configured") unless Auditors::Course::Stream.available? pending("needs auditors cassandra keyspace configured") unless Auditors::Course::Stream.available?
@request_id = UUIDSingleton.instance.generate @request_id = CanvasUUID.generate
RequestContextGenerator.stubs( :request_id => @request_id ) RequestContextGenerator.stubs( :request_id => @request_id )
@domain_root_account = Account.default @domain_root_account = Account.default

View File

@ -48,7 +48,7 @@ describe Api::V1::GradeChangeEvent do
before do before do
pending("needs auditors cassandra keyspace configured") unless Auditors::GradeChange::Stream.available? pending("needs auditors cassandra keyspace configured") unless Auditors::GradeChange::Stream.available?
@request_id = UUIDSingleton.instance.generate @request_id = CanvasUUID.generate
RequestContextGenerator.stubs( :request_id => @request_id ) RequestContextGenerator.stubs( :request_id => @request_id )
@domain_root_account = Account.default @domain_root_account = Account.default

View File

@ -22,7 +22,7 @@ describe Api::V1::PageView do
include Api::V1::PageView include Api::V1::PageView
before do before do
@request_id = UUIDSingleton.instance.generate @request_id = CanvasUUID.generate
RequestContextGenerator.stubs( :request_id => @request_id ) RequestContextGenerator.stubs( :request_id => @request_id )
@domain_root_account = Account.default @domain_root_account = Account.default

View File

@ -324,7 +324,7 @@ describe Attachment do
context "submit_to_scribd!" do context "submit_to_scribd!" do
before do before do
ScribdAPI.stubs(:upload).returns(UUIDSingleton.instance.generate) ScribdAPI.stubs(:upload).returns(CanvasUUID.generate)
end end
describe "submit_to_scribd job" do describe "submit_to_scribd job" do

View File

@ -107,7 +107,7 @@ describe Auditors::Authentication do
before do before do
@event2 = @pseudonym.shard.activate do @event2 = @pseudonym.shard.activate do
record = Auditors::Authentication::Record.new( record = Auditors::Authentication::Record.new(
'id' => UUIDSingleton.instance.generate, 'id' => CanvasUUID.generate,
'created_at' => 1.day.ago, 'created_at' => 1.day.ago,
'pseudonym' => @pseudonym, 'pseudonym' => @pseudonym,
'event_type' => 'login') 'event_type' => 'login')

View File

@ -102,7 +102,7 @@ describe CommunicationChannel do
end end
it "should set a confirmation code unless one has been set" do it "should set a confirmation code unless one has been set" do
CanvasUuid::Uuid.expects(:generate).at_least(1).returns('abc123') CanvasSlug.expects(:generate).at_least(1).returns('abc123')
communication_channel_model communication_channel_model
@cc.confirmation_code.should eql('abc123') @cc.confirmation_code.should eql('abc123')
end end

View File

@ -1452,7 +1452,7 @@ end
@request_id = opts[:request_id] || RequestContextGenerator.request_id @request_id = opts[:request_id] || RequestContextGenerator.request_id
unless @request_id unless @request_id
@request_id = UUIDSingleton.instance.generate @request_id = CanvasUUID.generate
RequestContextGenerator.stubs(:request_id => @request_id) RequestContextGenerator.stubs(:request_id => @request_id)
end end

View File

@ -482,7 +482,7 @@ class Job
end end
def create def create
self.id ||= UUIDSingleton.instance.generate self.id ||= CanvasUUID.generate
self.created_at = self.updated_at = Time.now.utc self.created_at = self.updated_at = Time.now.utc
save_job_to_redis save_job_to_redis
update_queues update_queues