Commit 833480da authored by Jacob Schatz's avatar Jacob Schatz Committed by Micaël Bergeron

Add tests for pseudo anonymous

parent e9c28fd0
require 'spec_helper'
describe Gitlab::Pseudonymity do
let!(:project) { create(:project) }
let(:base_dir) { Dir.mktmpdir }
subject(:pseudo) { Pseudonymity::Table.new }
after do
FileUtils.rm_rf(base_dir)
end
# create temp directory in before block
describe 'Pseudo tables' do
it 'outputs project tables to csv' do
pseudo.config["output"]["csv"] = base_dir
pseudo.config["tables"] = {
"projects" => {
"whitelist" => [
"id",
"name",
"path",
"description"
],
"pseudo" => [
"id"
]
}
}
expect(pseudo.config["output"]["csv"]).to eq(base_dir)
# grab the first table it outputs. There would only be 1.
project_table_file = pseudo.tables_to_csv[0]
# Ignore the `.` and `..` in the directory.
entry = Dir.entries(base_dir)[2]
expect(project_table_file.include? "projects_").to be true
expect(project_table_file.include? ".csv").to be true
expect(project_table_file.include? entry).to be true
columns = []
project_data = []
File.foreach(project_table_file).with_index do |line, line_num|
if line_num == 0
columns = line.split(",")
end
if line_num == 1
project_data = line.split(",")
break
end
end
# check if CSV columns are correct
expect(columns.to_set).to eq(["id", "name", "path", "description\n"].to_set)
# is it pseudonymous
expect(project_data[0]).not_to eq(1)
# sha 256 is 64 chars in length
expect(project_data[0].length).to eq(64)
end
end
end
......@@ -24,6 +24,8 @@ module Pseudonymity
end
class Table
attr_accessor :config
def initialize
@config = {}
@csv_output = ""
......@@ -31,8 +33,8 @@ module Pseudonymity
end
def tables_to_csv
tables = @config["tables"]
@csv_output = @config["output"]["csv"]
tables = config["tables"]
@csv_output = config["output"]["csv"]
if not File.directory?(@csv_output)
puts "No such directory #{@csv_output}"
return
......
......@@ -70,7 +70,7 @@ namespace :gitlab do
Gitlab::DowntimeCheck.new.check_and_print(migrations)
end
desc 'Output pseudonymity dump of selected table'
desc 'Output pseudonymity dump of selected tables'
task :pseudonymity_dump => :environment do
table = Pseudonymity::Table.new
table.tables_to_csv
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment