code stringlengths 23 2.05k | label_name stringlengths 6 7 | label int64 0 37 |
|---|---|---|
def current_database
return @current_database if defined? @current_database
if database = options[:database]
set_current_database(database)
else
raise "No database set for session. Call #use or #with before accessing the database"
end
end | CWE-400 | 2 |
it "drops the index that matches the key" do
indexes[name: 1].should be_nil
end | CWE-20 | 0 |
it "sets the object id's data" do
Moped::BSON::ObjectId.new(bytes).data.should == bytes
end | CWE-20 | 0 |
it "includes plaintext secret" do
expect(app.as_json).to include("secret" => "123123123")
end | CWE-862 | 8 |
it "has an empty list of dynamic seeds" do
cluster.dynamic_seeds.should be_empty
end | CWE-20 | 0 |
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 | CWE-400 | 2 |
it "returns nothing" do
socket.stub(connect: false)
cluster.sync_server(server).should be_empty
end | CWE-20 | 0 |
it "raises a connection failure exception" do
cluster.sync_server(server).should be_empty
end | CWE-20 | 0 |
def category_preferences_export
return enum_for(:category_preferences_export) unless block_given?
CategoryUser
.where(user_id: @current_user.id)
.select(:category_id, :notification_level, :last_seen_at)
.each do |cu|
yield [
cu.category_id,
piped_cate... | CWE-200 | 10 |
def discard_cookie!(headers)
Rack::Utils.delete_cookie_header!(headers, COOKIE_NAME, :path => '/')
end | CWE-200 | 10 |
it "yields the new session" do
session.stub(with: new_session)
session.new(new_options) do |session|
session.should eql new_session
end
end | CWE-400 | 2 |
def each
cursor = Cursor.new(session.with(retain_socket: true), operation)
cursor.to_enum.tap do |enum|
enum.each do |document|
yield document
end if block_given?
end
end | CWE-20 | 0 |
it "activates user invited via email with a token" do
invite = Fabricate(:invite, invited_by: Fabricate(:admin), email: 'walter.white@email.com', emailed_status: Invite.emailed_status_types[:sent])
user = InviteRedeemer.create_user_from_invite(invite: invite, email: invite.email, username: 'walter', nam... | CWE-863 | 11 |
def test_update_valid
put :update, {:id => Hostgroup.first, :hostgroup => { :name => Hostgroup.first.name }}, set_session_user
assert_redirected_to hostgroups_url
end | CWE-200 | 10 |
def authenticate!
unless Setting['oauth_active']
Rails.logger.warn 'Trying to authenticate with OAuth, but OAuth is not active'
return nil
end
unless (incoming_key = OAuth::RequestProxy.proxy(request).oauth_consumer_key) == Setting['oauth_consumer_key']
Rails.logger.warn "... | CWE-200 | 10 |
it "doesn't log in the user when not approved" do
SiteSetting.must_approve_users = true
get "/session/email-login/#{email_token.token}"
expect(response.status).to eq(200)
expect(CGI.unescapeHTML(response.body)).to include(
I18n.t("login.not_approved")
)
e... | CWE-287 | 4 |
def create_fixed_clamp_code(nbits, signed)
if nbits == 1 && signed == :signed
raise "signed bitfield must have more than one bit"
end
if signed == :signed
max = (1 << (nbits - 1)) - 1
min = -(max + 1)
else
min = 0
max = (1 << nbits... | CWE-400 | 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... | CWE-200 | 10 |
it "respects custom options" do
expect(app.as_json(except: :secret)).not_to include("secret")
expect(app.as_json(only: :id)).to match("id" => app.id)
end | CWE-862 | 8 |
def show
respond_to do |format|
format.html
format.json { render json: @application }
end
end | CWE-862 | 8 |
it 'supports group' do
topic = Fabricate(:topic, created_at: 3.months.ago)
post = Fabricate(:post, raw: 'hi this is a test 123 123', topic: topic)
group = Group.create!(name: "Like_a_Boss")
GroupUser.create!(user_id: post.user_id, group_id: group.id)
expect(Search.execute('group:like... | CWE-200 | 10 |
it "has an empty list of primaries" do
cluster.primaries.should be_empty
end | CWE-400 | 2 |
it "returns the query" do
query.limit(5).should eql query
end | CWE-20 | 0 |
it "queries a slave node" do
session.should_receive(:socket_for).with(:read).
and_return(socket)
session.query(query)
end | CWE-400 | 2 |
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... | CWE-863 | 11 |
def test_login_should_not_redirect_to_another_host
post :login, :username => 'jsmith', :password => 'jsmith', :back_url => 'http://test.foo/fake'
assert_redirected_to '/my/page'
end | CWE-20 | 0 |
def initialize(session, query_operation)
@session = session
@query_op = query_operation.dup
@get_more_op = Protocol::GetMore.new(
@query_op.database,
@query_op.collection,
0,
@query_op.limit
)
@kill_cursor_op = Protocol::KillCursors.new([0])
end | CWE-20 | 0 |
def self.taxonomy_conditions
org = Organization.expand(Organization.current) if SETTINGS[:organizations_enabled]
loc = Location.expand(Location.current) if SETTINGS[:locations_enabled]
conditions = {}
conditions[:organization_id] = Array(org).map { |o| o.subtree_ids }.flatten.uniq if org.pre... | CWE-200 | 10 |
it "fails when user is suspended" do
user.update!(
suspended_till: 2.days.from_now,
suspended_at: Time.zone.now
)
get "/session/email-login/#{email_token.token}"
expect(response.status).to eq(200)
expect(CGI.unescapeHTML(response.body)).to include(I18... | CWE-287 | 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 | CWE-400 | 2 |
it 'should return a second factor prompt' do
get "/session/email-login/#{email_token.token}"
expect(response.status).to eq(200)
response_body = CGI.unescapeHTML(response.body)
expect(response_body).to include(I18n.t(
"login.second_factor_title"
... | CWE-287 | 4 |
it "yields a new session" do
session.with(new_options) do |new_session|
new_session.should_not eql session
end
end | CWE-20 | 0 |
def execute(op)
mode = options[:consistency] == :eventual ? :read : :write
socket = socket_for(mode)
if safe?
last_error = Protocol::Command.new(
"admin", { getlasterror: 1 }.merge(safety)
)
socket.execute(op, last_error).documents.first.tap do |result|
... | CWE-20 | 0 |
def insert(documents)
documents = [documents] unless documents.is_a? Array
insert = Protocol::Insert.new(database.name, name, documents)
database.session.with(consistency: :strong) do |session|
session.execute insert
end
end | CWE-20 | 0 |
def more?
@get_more_op.cursor_id != 0
end | CWE-20 | 0 |
it "sets the current database" do
session.should_receive(:set_current_database).with(:admin)
session.use :admin
end | CWE-20 | 0 |
def Sendmail.call(path, arguments, destinations, mail)
IO.popen("#{path} #{arguments} #{destinations}", "w+") do |io|
io.puts mail.encoded.to_lf
io.flush
end
end | CWE-20 | 0 |
it "returns a new session" do
session.with(new_options).should_not eql session
end | CWE-400 | 2 |
def sync
known = known_addresses.shuffle
seen = {}
sync_seed = ->(seed) do
server = Server.new seed
unless seen[server.resolved_address]
seen[server.resolved_address] = true
hosts = sync_server(server)
hosts.each do |host|
sync_seed[ho... | CWE-400 | 2 |
it "returns the result of the block" do
session.with(new_options) { false }.should eq false
end | CWE-400 | 2 |
def private_message_reset_new
topic_query = TopicQuery.new(current_user)
if params[:topic_ids].present?
unless Array === params[:topic_ids]
raise Discourse::InvalidParameters.new(
"Expecting topic_ids to contain a list of topic ids"
)
end
topic_scope = topic_query... | CWE-863 | 11 |
def build_actions(actions, guardian, args)
return unless pending?
if guardian.can_approve?(target) || args[:approved_by_invite]
actions.add(:approve_user) do |a|
a.icon = 'user-plus'
a.label = "reviewables.actions.approve_user.title"
end
end
delete_user_actions(actions, r... | CWE-863 | 11 |
def valid?(user, password)
return false if user.blank?
if PasswordHash.legacy?(user.password, password)
update_password(user, password)
return true
end
PasswordHash.verified?(user.password, password)
end | CWE-863 | 11 |
it "returns the master connection" do
cluster.socket_for(:read).should eq socket
end | CWE-400 | 2 |
def as_json(options = {})
hash = super
hash["secret"] = plaintext_secret if hash.key?("secret")
hash
end | CWE-862 | 8 |
def default_ids_hash(populate_values = false)
ids = HashWithIndifferentAccess.new
hash_keys.each do |col|
ids[col] = populate_values ? Array(self.send(col)) : []
end
ids
end | CWE-200 | 10 |
def to_s
@@string_format % data
end | CWE-20 | 0 |
it "executes a simple query" do
session.should_receive(:simple_query).with(query.operation)
query.one
end | CWE-400 | 2 |
it "executes the operation on a slave node" do
session.should_receive(:socket_for).with(:read).
and_return(socket)
socket.should_receive(:execute).with(operation)
session.execute(operation)
end | CWE-20 | 0 |
it "delegates to the cluster" do
session.cluster.should_receive(:socket_for).with(:read)
session.send(:socket_for, :read)
end | CWE-400 | 2 |
it "drops all indexes for the collection" do
indexes[name: 1].should be_nil
indexes[age: -1].should be_nil
end | CWE-400 | 2 |
def initialize(string)
super("'#{string}' is not a valid object id.")
end | CWE-20 | 0 |
it "updates the selector to mongo's advanced selector" do
query.sort(a: 1)
query.operation.selector.should eq(
"$query" => selector,
"$orderby" => { a: 1 }
)
end | CWE-20 | 0 |
def get_user_archive_fields(user_archive)
user_archive_array = []
topic_data = user_archive.topic
user_archive = user_archive.as_json
topic_data = Topic.with_deleted.find_by(id: user_archive['topic_id']) if topic_data.nil?
return user_archive_array if topic_data.nil?
categories ... | CWE-200 | 10 |
it "drops the collection" do
database.should_receive(:command).with(drop: :users)
collection.drop
end | CWE-20 | 0 |
def approve_account_if_needed
if invited_user.present? && reviewable_user = ReviewableUser.find_by(target: invited_user, status: Reviewable.statuses[:pending])
reviewable_user.perform(
invite.invited_by,
:approve_user,
send_email: false,
approved_by_invite: true
)
e... | CWE-863 | 11 |
def setup_user
@request.session[:user] = users(:one).id
users(:one).roles = [Role.default, Role.find_by_name('Viewer')]
end | CWE-200 | 10 |
it "unmemoizes the current database" do
db = session.current_database
session.with(new_options) do |new_session|
new_session.current_database.should_not eql db
end
end | CWE-400 | 2 |
def split_path(request)
# Reparse the configuration if necessary.
readconfig
mount_name, path = request.key.split(File::Separator, 2)
raise(ArgumentError, "Cannot find file: Invalid path '#{mount_name}'") unless mount_name =~ %r{^[-\w]+$}
return nil unless mount = find_mount(mount_name, request... | CWE-200 | 10 |
def secondaries
servers.select(&:secondary?)
end | CWE-400 | 2 |
def redirect_back_or_default(default, options={})
back_url = params[:back_url].to_s
if back_url.present?
begin
uri = URI.parse(back_url)
# do not redirect user to another host or to the login or register page
if (uri.relative? || (uri.host == request.host)) && !uri.path.match(%r{... | CWE-20 | 0 |
it "adds the node to the master set" do
cluster.sync_server server
cluster.primaries.should include server
end | CWE-20 | 0 |
it "does not re-sync the cluster" do
cluster.should_receive(:sync).never
cluster.socket_for :write
end | CWE-20 | 0 |
it "instructs the cluster to reconnect" do
session.stub(with: new_session)
new_session.cluster.should_receive(:reconnect)
session.new(new_options)
end | CWE-20 | 0 |
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 | CWE-863 | 11 |
def filter_archived(list, user, archived: true)
# Executing an extra query instead of a sub-query because it is more
# efficient for the PG planner. Caution should be used when changing the
# query here as it can easily lead to an inefficient query.
group_ids = group_with_messages_ids(user)
... | CWE-863 | 11 |
it "returns the result of the block" do
session.with(new_options) { false }.should eq false
end | CWE-20 | 0 |
it "updates the selector to mongo's advanced selector" do
query.sort(a: 1)
query.operation.selector.should eq(
"$query" => selector,
"$orderby" => { a: 1 }
)
end | CWE-400 | 2 |
it "returns a session" do
session.with(new_options).should be_a Moped::Session
end | CWE-400 | 2 |
it "does not automatically approve users if must_approve_users is true" do
SiteSetting.must_approve_users = true
invite = Fabricate(:invite, email: 'test@example.com')
user = InviteRedeemer.create_user_from_invite(invite: invite, email: invite.email, username: 'test')
expect(user.approved).... | CWE-863 | 11 |
it 'should write the public key to disk if its the first time its been seen' do
@plugin.stubs(:lookup_config_option).with('learn_public_keys').returns('1')
@plugin.stubs(:lookup_config_option).with('publickey_dir').returns('ssh/pkd')
File.stubs(:directory?).with('ssh/pkd').returns(... | CWE-20 | 0 |
it "recognizes and generates #destroy" do
{ :delete => "/users/1" }.should route_to(:controller => "users", :action => "destroy", :id => "1")
end | CWE-200 | 10 |
def sync_server(server)
[].tap do |hosts|
socket = server.socket
if socket.connect
info = socket.simple_query Protocol::Command.new(:admin, ismaster: 1)
if info["ismaster"]
server.primary = true
end
if info["secondary"]
server.... | CWE-400 | 2 |
it "returns false" do
session.should_not be_safe
end | CWE-20 | 0 |
def filter_archived(list, user, archived: true)
list = list.joins(<<~SQL)
LEFT JOIN group_archived_messages gm ON gm.topic_id = topics.id
LEFT JOIN user_archived_messages um
ON um.user_id = #{user.id.to_i}
AND um.topic_id = topics.id
SQL
list =
if archived
... | CWE-863 | 11 |
it "should should include the IndirectionHooks module in its indirection" do
Puppet::FileServing::Content.indirection.singleton_class.included_modules.should include(Puppet::FileServing::IndirectionHooks)
end | CWE-200 | 10 |
it "returns nothing" do
socket.stub(connect: false)
cluster.sync_server(server).should be_empty
end | CWE-400 | 2 |
def drop
command dropDatabase: 1
end | CWE-20 | 0 |
def test_edit
get :edit, {:id => Hostgroup.first}, set_session_user
assert_template 'edit'
end | CWE-200 | 10 |
def self.publish_unread(post)
return unless post.topic.regular?
# TODO at high scale we are going to have to defer this,
# perhaps cut down to users that are around in the last 7 days as well
group_ids =
if post.post_type == Post.types[:whisper]
[Group::AUTO_GROUPS[:staff]]
else... | CWE-200 | 10 |
it "stores the collection name" do
collection.name.should eq :users
end | CWE-20 | 0 |
def from_string(string)
raise Errors::InvalidObjectId.new(string) unless legal?(string)
data = []
12.times { |i| data << string[i*2, 2].to_i(16) }
new data
end | CWE-20 | 0 |
def generate(time, inc = 0)
pid = Process.pid % 0xFFFF
[
time >> 24 & 0xFF, # 4 bytes time (network order)
time >> 16 & 0xFF,
time >> 8 & 0xFF,
time & 0xFF,
@machine_id[0], # 3 bytes machine
@machine_id[1],
... | CWE-400 | 2 |
def sync
known = known_addresses.shuffle
seen = {}
sync_seed = ->(seed) do
server = Server.new seed
unless seen[server.resolved_address]
seen[server.resolved_address] = true
hosts = sync_server(server)
hosts.each do |host|
sync_seed[ho... | CWE-20 | 0 |
it 'should overwrite the existing public key if overwrite_stored_key is set' do
@plugin.stubs(:lookup_config_option).with('learn_public_keys').returns('1')
@plugin.stubs(:lookup_config_option).with('publickey_dir').returns('ssh/pkd')
@plugin.stubs(:lookup_config_option).with('overw... | CWE-20 | 0 |
def update(change, flags = nil)
update = Protocol::Update.new(
operation.database,
operation.collection,
operation.selector,
change,
flags: flags
)
session.with(consistency: :strong) do |session|
session.execute update
end
end | CWE-400 | 2 |
it "should fail when a protocol other than :puppet or :file is used" do
@request.stubs(:protocol).returns "http"
proc { @object.select_terminus(@request) }.should raise_error(ArgumentError)
end | CWE-200 | 10 |
def initialize(seeds, direct = false)
@seeds = seeds
@direct = direct
@servers = []
@dynamic_seeds = []
end | CWE-400 | 2 |
it "updates a hostgroup with a parent parameter, allows empty values" do
child = FactoryGirl.create(:hostgroup, :parent => @base)
as_admin do
assert_equal "original", child.parameters["x"]
end
post :update, {"id" => child.id, "hostgroup" => {"name" => child.name,
... | CWE-200 | 10 |
it "returns the count" do
database.stub(command: { "n" => 4 })
query.count.should eq 4
end | CWE-400 | 2 |
it "executes a distinct command" do
database.should_receive(:command).with(
distinct: collection.name,
key: "name",
query: selector
).and_return("values" => [ "durran", "bernerd" ])
query.distinct(:name)
end | CWE-20 | 0 |
it "delegates to #with" do
session.should_receive(:with).with(new_options).and_return(new_session)
session.new(new_options)
end | CWE-20 | 0 |
it "upserts the record matching selector with change" do
query.should_receive(:update).with(change, [:upsert])
query.upsert change
end | CWE-20 | 0 |
it "yields a session" do
session.with(new_options) do |new_session|
new_session.should be_a Moped::Session
end
end | CWE-400 | 2 |
def decode_compact_serialized(input, private_key_or_secret, algorithms = nil, encryption_methods = nil, _allow_blank_payload = false)
unless input.count('.') + 1 == NUM_OF_SEGMENTS
raise InvalidFormat.new("Invalid JWE Format. JWE should include #{NUM_OF_SEGMENTS} segments.")
end
... | CWE-287 | 4 |
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 | CWE-20 | 0 |
it "changes the $orderby" do
query.sort(a: 1)
query.sort(a: 2)
query.operation.selector.should eq(
"$query" => selector,
"$orderby" => { a: 2 }
)
end | CWE-400 | 2 |
it "yields all documents in the cursor" do
cursor = Moped::Cursor.allocate
cursor.stub(:to_enum).and_return([1, 2].to_enum)
Moped::Cursor.stub(new: cursor)
query.to_a.should eq [1, 2]
end | CWE-400 | 2 |
it "raises no exception" do
lambda do
cluster.sync_server server
end.should_not raise_exception
end | CWE-20 | 0 |
it "stores the collection" do
query.collection.should eq collection
end | CWE-400 | 2 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.