code stringlengths 12 2.05k | label_name stringclasses 5
values | label int64 0 4 |
|---|---|---|
def process_cors(env)
resource, error = match_resource(env)
if resource
Result.hit(env)
cors = resource.to_headers(env)
cors
else
Result.miss(env, error)
nil
end
end | Base | 1 |
it "drops the collection" do
database.should_receive(:command).with(drop: :users)
collection.drop
end | Class | 2 |
def delete_statistics_group
Log.add_info(request, params.inspect)
group_id = params[:group_id]
if group_id.nil? or group_id.empty?
@group_ids = Research.get_statistics_groups
render(:partial => 'ajax_statistics_groups', :layout => false)
return
end
@group_ids = Research.delet... | Base | 1 |
def protected!
if not PCSAuth.loginByToken(session, cookies) and not PCSAuth.isLoggedIn(session)
# If we're on /managec/<cluster_name>/main we redirect
match_expr = "/managec/(.*)/(.*)"
mymatch = request.path.match(match_expr)
on_managec_main = false
if mymatch and mymatch.length >= ... | Compound | 4 |
it "creates an index with a generated name" do
indexes.create(key)
indexes[key]["name"].should eq "location.latlong_2d_name_1_age_-1"
end | Class | 2 |
it "sets the :database option" do
session.use :admin
session.options[:database].should eq(:admin)
end | Class | 2 |
it "returns the query" do
query.limit(5).should eql query
end | Class | 2 |
def self.destroy_by_user(user_id, add_con=nil)
SqlHelper.validate_token([user_id])
con = "user_id=#{user_id}"
con << " and (#{add_con})" unless add_con.nil? or add_con.empty?
mail_accounts = MailAccount.where(con).to_a
mail_accounts.each do |mail_account|
mail_account.destroy
end
en... | Base | 1 |
it 'correctly exports the CategoryUser table' do
data, _csv_out = make_component_csv
expect(data.find { |r| r['category_id'] == category.id }).to be_nil
expect(data.length).to eq(4)
data.sort! { |a, b| a['category_id'].to_i <=> b['category_id'].to_i }
expect(data[0][:category_id]).to... | Class | 2 |
def get_node_status(session, cib_dom)
node_status = {
:cluster_name => $cluster_name,
:groups => [],
:constraints => {
# :rsc_location => [],
# :rcs_colocation => [],
# :rcs_order => []
},
:cluster_settings => {},
:need_ring1_address => need_ring1_addr... | Compound | 4 |
def set_attachment
Log.add_info(request, params.inspect)
created = false
if params[:id].nil? or params[:id].empty?
@item = Item.new_info(0)
@item.attributes = params[:item]
@item.user_id = @login_user.id
@item.title = t('paren.no_title')
[:attachment0, :attachment1].each d... | Base | 1 |
def add_acl_permission(session, acl_role_id, perm_type, xpath_id, query_id)
stdout, stderror, retval = run_cmd(
session, PCS, "acl", "permission", "add", acl_role_id.to_s, perm_type.to_s,
xpath_id.to_s, query_id.to_s
)
if retval != 0
if stderror.empty?
return "Error adding permission"
else
... | Compound | 4 |
def verify_signature(jwt)
head = token_head(jwt)
# Make sure the algorithm is supported and get the decode key.
if head[:alg] == 'RS256'
[rs256_decode_key(head[:kid]), head[:alg]]
elsif head[:alg] == 'HS256'
[@client_secret, head[:alg]]
else
r... | Base | 1 |
def add_statistics_group
Log.add_info(request, params.inspect)
current_id = params[:current_id]
if !params[:thetisBoxSelKeeper].nil?
group_id = params[:thetisBoxSelKeeper].split(':').last
end
if group_id.nil? or group_id.empty?
@group_ids = Research.get_statistics_groups
rend... | Base | 1 |
def remove
delete = Protocol::Delete.new(
operation.database,
operation.collection,
operation.selector,
flags: [:remove_first]
)
session.with(consistency: :strong) do |session|
session.execute delete
end
end | Class | 2 |
def remove_acl_permission(session, acl_perm_id)
stdout, stderror, retval = run_cmd(
session, PCS, "acl", "permission", "delete", acl_perm_id.to_s
)
if retval != 0
if stderror.empty?
return "Error removing permission"
else
return stderror.join("\n").strip
end
end
return ""
end | Compound | 4 |
def quote_column_name(name) #:nodoc:
%Q("#{name}")
end | Base | 1 |
def process_invitation
approve_account_if_needed
add_to_private_topics_if_invited
add_user_to_groups
send_welcome_message
notify_invitee
end | Class | 2 |
def generation_time
Time.at(@data.pack("C4").unpack("N")[0]).utc
end | Class | 2 |
it "executes the operation on the master node" do
session.should_receive(:socket_for).with(:write).
and_return(socket)
socket.should_receive(:execute).with(operation)
session.execute(operation)
end | Class | 2 |
def get_current_node_name()
stdout, stderror, retval = run_cmd(
PCSAuth.getSuperuserSession, CRM_NODE, "-n"
)
if retval == 0 and stdout.length > 0
return stdout[0].chomp()
end
return ""
end | Compound | 4 |
def self.getUsersGroups(username)
stdout, stderr, retval = run_cmd(
getSuperuserSession, "id", "-Gn", username
)
if retval != 0
$logger.info(
"Unable to determine groups of user '#{username}': #{stderr.join(' ').strip}"
)
return [false, []]
end
return [true, stdout.... | Compound | 4 |
def self.get_account_roots_for(user)
return nil if user.nil?
if user.kind_of?(User)
user_id = user.id
else
user_id = user.to_s
end
SqlHelper.validate_token([user_id])
con = []
con << "(user_id=#{user_id})"
con << "(xtype='#{MailFolder::XTYPE_ACCOUNT_ROOT}')"
order_... | Base | 1 |
it "inserts the document" do
session.should_receive(:execute).with do |insert|
insert.documents.should eq [{a: 1}]
end
collection.insert(a: 1)
end | Class | 2 |
def get_fence_levels(session, cib_dom=nil)
unless cib_dom
cib_dom = get_cib_dom(session)
return {} unless cib_dom
end
fence_levels = {}
cib_dom.elements.each(
'/cib/configuration/fencing-topology/fencing-level'
) { |e|
target = e.attributes['target']
fence_levels[target] ||= []
fence_... | Compound | 4 |
def fast_forward_to_first_boundary
loop do
read_buffer = @io.gets
break if read_buffer == full_boundary
raise EOFError, "bad content body" if read_buffer.nil?
end
end | Class | 2 |
def send_password
Log.add_info(request, params.inspect)
begin
users = User.where("email='#{params[:thetisBoxEdit]}'").to_a
rescue => evar
end
if users.nil? or users.empty?
Log.add_error(request, evar)
flash[:notice] = 'ERROR:' + t('email.address_not_found')
else
user_... | Base | 1 |
def parse(socket=nil)
@socket = socket
begin
@peeraddr = socket.respond_to?(:peeraddr) ? socket.peeraddr : []
@addr = socket.respond_to?(:addr) ? socket.addr : []
rescue Errno::ENOTCONN
raise HTTPStatus::EOFError
end
read_request_line(socket)
if @http_ver... | Base | 1 |
def protected!
gui_request = ( # these are URLs for web pages
request.path == '/' or
request.path == '/manage' or
request.path == '/permissions' or
request.path.match('/managec/.+/main')
)
if request.path.start_with?('/remote/') or request.path == '/run_pcs'
@auth_user = PCSA... | Compound | 4 |
def gate_process
HistoryHelper.keep_last(request)
@login_user = User.find(session[:login_user_id])
begin
if @login_user.nil? \
or @login_user.time_zone.nil? or @login_user.time_zone.empty?
unless THETIS_USER_TIMEZONE_DEFAULT.nil? or THETIS_USER_TIMEZONE_DEFAULT.empty?
... | Base | 1 |
def sanitize(html, options = {})
return unless html
return html if html.empty?
Loofah.fragment(html).tap do |fragment|
remove_xpaths(fragment, XPATHS_TO_REMOVE)
end.text(options)
end | Base | 1 |
def spoofed?
if has_name? && has_extension? && media_type_mismatch? && mapping_override_mismatch?
Paperclip.log("Content Type Spoof: Filename #{File.basename(@name)} (#{supplied_file_content_types}), content type discovered from file command: #{calculated_content_type}. See documentation to allow this... | Base | 1 |
def remove(server)
servers.delete(server)
end | Class | 2 |
def test_update_valid
put :update, {:id => Hostgroup.first, :hostgroup => { :name => Hostgroup.first.name }}, set_session_user
assert_redirected_to hostgroups_url
end | Class | 2 |
it "yields a new session" do
session.with(new_options) do |new_session|
new_session.should_not eql session
end
end | Class | 2 |
it 'authenticates successfuly' do
basic_authorize 'a', 'b'
get '/'
assert_equal 200, last_response.status
end | Base | 1 |
def self.find_term(user_id, start_date, end_date)
SqlHelper.validate_token([user_id])
start_s = start_date.strftime(Schedule::SYS_DATE_FORM)
end_s = end_date.strftime(Schedule::SYS_DATE_FORM)
con = "(user_id=#{user_id}) and (date >= '#{start_s}') and (date <= '#{end_s}')"
ary = Timecard.where(c... | Base | 1 |
def destroy
Log.add_info(request, params.inspect)
if params[:check_user].nil?
list
render(:action => 'list')
return
end
count = 0
params[:check_user].each do |user_id, value|
if value == '1'
begin
User.destroy(user_id)
rescue => evar
L... | Base | 1 |
detectMimeType(filename) {
if (!filename) {
return defaultMimeType;
}
let parsed = path.parse(filename);
let extension = (parsed.ext.substr(1) || parsed.name || '')
.split('?')
.shift()
.trim()
.toLowerCase();
let v... | Base | 1 |
def get_crm_mon_dom(session)
begin
stdout, _, retval = run_cmd(
session, CRM_MON, '--one-shot', '-r', '--as-xml'
)
if retval == 0
return REXML::Document.new(stdout.join("\n"))
end
rescue
$logger.error 'Failed to parse crm_mon.'
end
return nil
end | Compound | 4 |
def build_command_line(command, params = nil)
return command.to_s if params.nil? || params.empty?
"#{command} #{assemble_params(sanitize(params))}"
end | Base | 1 |
def create
Log.add_info(request, params.inspect)
parent_id = params[:selectedFolderId]
unless Folder.check_user_auth(parent_id, @login_user, 'w', true)
flash[:notice] = 'ERROR:' + t('folder.need_auth_to_modify')
render(:partial => 'ajax_folder_entry', :layout => false)
return
end
... | Base | 1 |
def each
documents = query @query_op
documents.each { |doc| yield doc }
while more?
return kill if limited? && @get_more_op.limit <= 0
documents = query @get_more_op
documents.each { |doc| yield doc }
end
end | Class | 2 |
it "inserts the documents" do
session.should_receive(:execute).with do |insert|
insert.documents.should eq [{a: 1}, {b: 2}]
end
collection.insert([{a: 1}, {b: 2}])
end | Class | 2 |
def add_fence_level_remote(params, request, session)
if not allowed_for_local_cluster(session, Permissions::WRITE)
return 403, 'Permission denied'
end
retval, stdout, stderr = add_fence_level(
session, params["level"], params["devices"], params["node"], params["remove"]
)
if retval == 0
return [20... | Compound | 4 |
it "does not raise error if record is not pending" do
reviewable = ReviewableUser.needs_review!(target: Fabricate(:user, email: invite.email), created_by: invite.invited_by)
reviewable.status = Reviewable.statuses[:ignored]
reviewable.save!
invite_redeemer.redeem
reviewabl... | Class | 2 |
it "returns the index with the provided key" do
indexes[name: 1]["name"].should eq "name_1"
end | Class | 2 |
it "delegates to the current database" do
database = mock(Moped::Database)
session.should_receive(:current_database).and_return(database)
database.should_receive(:drop)
session.drop
end | Class | 2 |
it "has an empty list of servers" do
cluster.servers.should be_empty
end | Class | 2 |
it "yields all indexes on the collection" do
indexes.to_a.should eq \
session[:"system.indexes"].find(ns: "moped_test.users").to_a
end | Class | 2 |
def get_tokens(params, request, session)
# pcsd runs as root thus always returns hacluster's tokens
if not allowed_for_local_cluster(session, Permissions::FULL)
return 403, 'Permission denied'
end
return [200, JSON.generate(read_tokens)]
end | Compound | 4 |
def deliver!(mail)
envelope_from = mail.return_path || mail.sender || mail.from_addrs.first
return_path = "-f " + '"' + envelope_from.escape_for_shell + '"' if envelope_from
arguments = [settings[:arguments], return_path].compact.join(" ")
self.class.call(settings[:location], arguments, ma... | Class | 2 |
def target_uri?(target)
::Asciidoctor::Helpers.uriish?(target)
end | Base | 1 |
it "instructs the cluster to reconnect" do
session.stub(with: new_session)
new_session.cluster.should_receive(:reconnect)
session.new(new_options)
end | Class | 2 |
it "queries a slave node" do
session.should_receive(:socket_for).with(:read).
and_return(socket)
session.query(query)
end | Class | 2 |
it "should raise an error if the image fails an integrity check when downloaded" do
stub_request(:get, "www.example.com/test.jpg").to_return(body: File.read(file_path("test.jpg")))
expect(running {
@instance.remote_image_url = "http://www.example.com/test.jpg"
}).to raise_error(CarrierWav... | Base | 1 |
it 'returns correct link' do
data = {
cutoff: false,
user: 'Julia Nguyen',
comment: 'Hello',
typename: 'typename',
type: 'type_comment_moment',
typeid: 1,
commentable_id: 1
}
expect(comment_link(uniqueid, data)).to eq('<a id="uniqueid" href="... | Base | 1 |
def self.get_default_for(user_id, xtype=nil)
SqlHelper.validate_token([user_id, xtype])
con = []
con << "(user_id=#{user_id})"
con << '(is_default=1)'
con << "(xtype='#{xtype}')" unless xtype.blank?
where = ''
unless con.nil? or con.empty?
where = 'where ' + con.join(' and ')
... | Base | 1 |
def resource_master(params, request, session)
if not allowed_for_local_cluster(session, Permissions::WRITE)
return 403, 'Permission denied'
end
unless params[:resource_id]
return [400, 'resource_id has to be specified.']
end
_, stderr, retval = run_cmd(
session, PCS, 'resource', 'master', params[... | Compound | 4 |
it "does not drop other indexes" do
indexes[age: -1].should_not be_nil
end | Class | 2 |
def escape_javascript(javascript)
javascript = javascript.to_s
if javascript.empty?
result = ""
else
result = javascript.gsub(/(\\|<\/|\r\n|\342\200\250|\342\200\251|[\n\r"'])/u, JS_ESCAPE_MAP)
end
javascript.html_safe? ? result.html_safe : result
... | Variant | 0 |
def self.reminders(options={})
days = options[:days] || 7
project = options[:project] ? Project.find(options[:project]) : nil
tracker = options[:tracker] ? Tracker.find(options[:tracker]) : nil
target_version_id = options[:version] ? Version.named(options[:version]).pluck(:id) : nil
if options[:ve... | Class | 2 |
def get_sw_versions(params, request, session)
versions = {
"rhel" => get_rhel_version(),
"pcs" => get_pcsd_version(),
"pacemaker" => get_pacemaker_version(),
"corosync" => get_corosync_version(),
"cman" => get_cman_version(),
}
return JSON.generate(versions)
end | Compound | 4 |
def unfold(string)
string.gsub(/#{CRLF}#{WSP}+/, ' ').gsub(/#{WSP}+/, ' ')
end | Base | 1 |
it "upserts the record matching selector with change" do
query.should_receive(:update).with(change, [:upsert])
query.upsert change
end | Class | 2 |
it "sets the current database" do
session.should_receive(:set_current_database).with(:admin)
session.use :admin
end | Class | 2 |
def getResourceAgents(session)
resource_agent_list = {}
stdout, stderr, retval = run_cmd(session, PCS, "resource", "list", "--nodesc")
if retval != 0
$logger.error("Error running 'pcs resource list --nodesc")
$logger.error(stdout + stderr)
return {}
end
agents = stdout
agents.each { |a|
ra ... | Compound | 4 |
def get_configs(params, request, session)
if not allowed_for_local_cluster(session, Permissions::FULL)
return 403, 'Permission denied'
end
if not $cluster_name or $cluster_name.empty?
return JSON.generate({'status' => 'not_in_cluster'})
end
if params[:cluster_name] != $cluster_name
return JSON.gen... | Compound | 4 |
def node_standby(params, request, session)
if params[:name]
code, response = send_request_with_token(
session, params[:name], 'node_standby', true, {"node"=>params[:name]}
)
# data={"node"=>params[:name]} for backward compatibility with older versions of pcs/pcsd
else
if not allowed_for_local_... | Compound | 4 |
def self.run_gpg(*args)
fragments = [
'gpg',
'--no-default-keyring'
] + args
command_line = fragments.join(' ')
output_file = Tempfile.new('gpg-output')
begin
output_file.close
result = system("#{command_line} > #{output_file.path} 2>&1")
ensure
... | Base | 1 |
def reactions_given
params.require(:username)
user = fetch_user_from_params(include_inactive: current_user.try(:staff?) || (current_user && SiteSetting.show_inactive_accounts))
raise Discourse::NotFound unless guardian.can_see_profile?(user)
reaction_users = DiscourseReactions::ReactionUser... | Class | 2 |
it "sets the generation time" do
time = Time.at((Time.now.utc - 64800).to_i).utc
Moped::BSON::ObjectId.new(nil, time).generation_time.should == time
end | Class | 2 |
def self.new string_or_io
from_document Nokogiri::XML(string_or_io)
end | Base | 1 |
def activity_user
user = current_user.pref[:activity_user]
if user && user != "all_users"
user = if user =~ /@/ # email
User.where(:email => user).first
else # first_name middle_name last_name any_name
name_query = if user.include?(" ")
user.name_permutations.map{... | Base | 1 |
it "stores the collection name" do
collection.name.should eq :users
end | Class | 2 |
it "should redeem the invite if invited by non staff and approve if staff not required to approve" do
inviter = invite.invited_by
user = invite_redeemer.redeem
expect(user.name).to eq(name)
expect(user.username).to eq(username)
expect(user.invited_by).to eq(inviter)
expect(invit... | Class | 2 |
def cluster_stop(params, request, session)
if params[:name]
params_without_name = params.reject {|key, value|
key == "name" or key == :name
}
code, response = send_request_with_token(
session, params[:name], 'cluster_stop', true, params_without_name
)
else
if not allowed_for_local_cl... | Compound | 4 |
def query(operation)
reply = session.query operation
@get_more_op.limit -= reply.count if limited?
@get_more_op.cursor_id = reply.cursor_id
@kill_cursor_op.cursor_ids = [reply.cursor_id]
reply.documents
end | Class | 2 |
def self.get_tree(klass, tree, conditions, node_id, order_by)
SqlHelper.validate_token([node_id])
if conditions.nil?
con = ''
else
con = Marshal.load(Marshal.dump(conditions)) + ' and '
end
con << "(parent_id=#{node_id})"
tree[node_id] = klass.where(con).order(order_by).to_a
... | Base | 1 |
it "only aquires the socket once" do
session.cluster.should_receive(:socket_for).
with(:read).once.and_return(mock(Moped::Socket))
session.send(:socket_for, :read)
session.send(:socket_for, :read)
end | Class | 2 |
def validate_each(record, attribute, value)
adapter = Paperclip.io_adapters.for(value)
if Paperclip::MediaTypeSpoofDetector.using(adapter, value.original_filename).spoofed?
record.errors.add(attribute, :spoofed_media_type)
end
end | Base | 1 |
it "can set password" do
user = InviteRedeemer.new(invite: invite, email: invite.email, username: username, name: name, password: password).redeem
expect(user).to have_password
expect(user.confirm_password?(password)).to eq(true)
expect(user.approved).to eq(true)
end | Class | 2 |
def setup_user(operation, type = "", search = nil, user = :one)
@one = users(user)
as_admin do
permission = Permission.find_by_name("#{operation}_#{type}") || FactoryGirl.create(:permission, :name => "#{operation}_#{type}")
filter = FactoryGirl.build(:filter, :search => search)
filter.permis... | Class | 2 |
it "only aquires the socket once" do
session.cluster.should_receive(:socket_for).
with(:read).once.and_return(mock(Moped::Socket))
session.send(:socket_for, :read)
session.send(:socket_for, :read)
end | Class | 2 |
it "returns a random slave connection" do
secondaries = [server]
cluster.stub(secondaries: secondaries)
secondaries.should_receive(:sample).and_return(server)
cluster.socket_for(:read).should eq socket
end | Class | 2 |
def initialize(string)
super("'#{string}' is not a valid object id.")
end | Class | 2 |
def self.exists_copies_folder?(user_id)
my_folder = User.get_my_folder(user_id)
unless my_folder.nil?
con = "(parent_id=#{my_folder.id}) and (name='#{Item.copies_folder}')"
begin
copies_folder = Folder.where(con).first
rescue
end
end
return !copies_folder.nil?
end | Base | 1 |
it "handles Symbol keys" do
cl = subject.build_command_line("true", :abc => "def")
expect(cl).to eq "true --abc def"
end | Base | 1 |
it "returns only published articles" do
article = create(:article)
create(:comment, article: article)
unpublished_article = create(:article, state: "draft")
create(:comment, article: unpublished_article)
expect(described_class.published).to eq([article])
expect(described_class.be... | Class | 2 |
def require_smart_proxy_or_login(features = nil)
features = features.call if features.respond_to?(:call)
allowed_smart_proxies = features.blank? ? SmartProxy.all : SmartProxy.with_features(*features)
if !Setting[:restrict_registered_smart_proxies] || auth_smart_proxy(allowed_smart_proxies, Setting[:requi... | Class | 2 |
it 'should return nil if there is not key' do
expect(jwt_validator.jwks_key(:auth0, jwks_kid)).to eq(nil)
end | Base | 1 |
def process
# We don't want any tracking back in the fs. Unlikely, but there
# you go.
client = self.host.gsub("..",".")
dir = File.join(Puppet[:reportdir], client)
if ! FileTest.exists?(dir)
FileUtils.mkdir_p(dir)
FileUtils.chmod_R(0750, dir)
end
# Now store the report.
... | Base | 1 |
it "recognizes and generates #destroy" do
{ :delete => "/users/1" }.should route_to(:controller => "users", :action => "destroy", :id => "1")
end | Class | 2 |
def set_corosync_conf(params, request, session)
if not allowed_for_local_cluster(session, Permissions::FULL)
return 403, 'Permission denied'
end
if params[:corosync_conf] != nil and params[:corosync_conf].strip != ""
Cfgsync::CorosyncConf.backup()
Cfgsync::CorosyncConf.from_text(params[:corosync_conf]... | Compound | 4 |
def show_tree
Log.add_info(request, params.inspect)
if !@login_user.nil? and @login_user.admin?(User::AUTH_FOLDER)
@group_id = nil
if !params[:thetisBoxSelKeeper].nil?
@group_id = params[:thetisBoxSelKeeper].split(':').last
elsif !params[:group_id].nil? and !params[:group_id].empty... | Base | 1 |
it "should choose :file_server when the settings name is 'puppet' and no server is specified" do
modules = mock 'modules'
@request.expects(:protocol).returns "puppet"
@request.expects(:server).returns nil
Puppet.settings.expects(:value).with(:name).returns "puppet"
@object... | Class | 2 |
def spree_current_user
@spree_current_user ||= Spree.user_class.find_by(id: doorkeeper_token.resource_owner_id) if doorkeeper_token
end | Base | 1 |
def test_execute_details_cleans_text
spec_fetcher do |fetcher|
fetcher.spec 'a', 2 do |s|
s.summary = 'This is a lot of text. ' * 4
s.authors = ["Abraham Lincoln \u0001", "\u0002 Hirohito"]
s.homepage = "http://a.example.com/\u0003"
end
fetcher.legacy_platform
end
... | Base | 1 |
it "stores the selector" do
query.selector.should eq selector
end | Class | 2 |
it "returns false" do
session.should_not be_safe
end | Class | 2 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.