Quellcode durchsuchen

Better faketime

new-scoring
aeris vor 2 Jahren
Ursprung
Commit
41c6f85a5d

+ 3
- 2
Makefile Datei anzeigen

@@ -8,7 +8,8 @@ RUBY_VERSION = $(RUBY_MAJOR_VERSION).3
8 8
 RUBY_NAME = ruby-$(RUBY_VERSION)
9 9
 RUBY_DIR = build/$(RUBY_NAME)
10 10
 RUBY_OPENSSL_EXT_DIR = $(RUBY_DIR)/ext/openssl
11
-RUBY_LIB_DIR = $(RBENV_ROOT)/versions/$(RUBY_VERSION)-cryptcheck/lib/ruby/$(RUBY_MAJOR_VERSION).0
11
+RBENV_DIR = $(RBENV_ROOT)/versions/$(RUBY_VERSION)-cryptcheck
12
+RUBY_LIB_DIR = $(RBENV_DIR)/lib/ruby/$(RUBY_MAJOR_VERSION).0
12 13
 RBENV_ROOT ?= ~/.rbenv
13 14
 export LIBRARY_PATH = $(PWD)/lib
14 15
 export C_INCLUDE_PATH = $(PWD)/$(OPENSSL_DIR)/include
@@ -101,7 +102,7 @@ lib/openssl.so: $(RUBY_OPENSSL_EXT_DIR)/openssl.so
101 102
 ext: lib/openssl.so
102 103
 
103 104
 spec/faketime/libfaketime.so: spec/faketime/faketime.c spec/faketime/faketime.h
104
-	$(CC) -shared -fPIC $^ -o $@ -ldl -std=c99 -Werror -Wall
105
+	$(CC) $^ -o $@ -shared -fPIC -ldl -std=c99 -Werror -Wall
105 106
 lib/libfaketime.so: spec/faketime/libfaketime.so
106 107
 	ln -fs ../$< $@
107 108
 faketime: lib/libfaketime.so

spec/cryptcheck/cert_spec.rb → spec/cryptcheck/tls/cert_spec.rb Datei anzeigen

@@ -7,7 +7,7 @@ describe CryptCheck::Tls::Cert do
7 7
 
8 8
 	describe '::trusted?' do
9 9
 		it 'must accept valid certificate' do
10
-			FakeTime.freeze_during Time.utc(2000, 1, 1) do
10
+			FakeTime.freeze Time.utc(2000, 1, 1) do
11 11
 				cert, *chain, ca = load_chain %w(ecdsa-prime256v1 intermediate ca)
12 12
 				trust            = ::CryptCheck::Tls::Cert.trusted? cert, chain, roots: ca
13 13
 				expect(trust).to eq :trusted
@@ -34,7 +34,7 @@ describe CryptCheck::Tls::Cert do
34 34
 		end
35 35
 
36 36
 		it 'must reject expired certificate' do
37
-			FakeTime.freeze_during Time.utc(2002, 1, 1) do
37
+			FakeTime.freeze Time.utc(2002, 1, 1) do
38 38
 				cert, *chain, ca = load_chain %w(ecdsa-prime256v1 intermediate ca)
39 39
 				trust            = ::CryptCheck::Tls::Cert.trusted? cert, chain, roots: ca
40 40
 				expect(trust).to eq 'certificate has expired'
@@ -42,7 +42,7 @@ describe CryptCheck::Tls::Cert do
42 42
 		end
43 43
 
44 44
 		it 'must reject not yet valid certificate' do
45
-			FakeTime.freeze_during Time.utc(1999, 1, 1) do
45
+			FakeTime.freeze Time.utc(1999, 1, 1) do
46 46
 				cert, *chain, ca = load_chain %w(ecdsa-prime256v1 intermediate ca)
47 47
 				trust            = ::CryptCheck::Tls::Cert.trusted? cert, chain, roots: ca
48 48
 				expect(trust).to eq 'certificate is not yet valid'

+ 1
- 1
spec/cryptcheck/tls/server_spec.rb Datei anzeigen

@@ -2,7 +2,7 @@ require 'faketime'
2 2
 
3 3
 describe CryptCheck::Tls::Server do
4 4
 	before :all do
5
-		FakeTime.freeze Time.utc(2000, 1, 1).to_i
5
+		FakeTime.freeze Time.utc(2000, 1, 1)
6 6
 	end
7 7
 
8 8
 	after :all do

+ 10
- 8
spec/faketime.rb Datei anzeigen

@@ -4,22 +4,24 @@ module FakeTime
4 4
 	extend FFI::Library
5 5
 	ffi_lib 'faketime'
6 6
 
7
-	def self.freeze(_)
7
+	def self._freeze(_)
8 8
 		#This is a stub, used for indexing
9 9
 	end
10 10
 	def self.unfreeze
11 11
 		#This is a stub, used for indexing
12 12
 	end
13 13
 
14
-	attach_function :freeze, [:ulong], :void
14
+	attach_function :_freeze, [:ulong], :void
15 15
 	attach_function :unfreeze, [], :void
16 16
 
17
-	def self.freeze_during(time, &block)
18
-		self.freeze time.to_i
19
-		begin
20
-			return block.call
21
-		ensure
22
-			self.unfreeze
17
+	def self.freeze(time)
18
+		self._freeze time.to_i
19
+		if block_given?
20
+			begin
21
+				return yield
22
+			ensure
23
+				self.unfreeze
24
+			end
23 25
 		end
24 26
 	end
25 27
 end

+ 1
- 1
spec/faketime/faketime.c Datei anzeigen

@@ -9,7 +9,7 @@ time_t frozen_time = 0;
9 9
 typedef time_t (*orig_time_f_type)(time_t*);
10 10
 orig_time_f_type orig_time = NULL;
11 11
 
12
-void freeze(unsigned long time) {
12
+void _freeze(unsigned long time) {
13 13
 	frozen_time = (time_t)time;
14 14
 	frozen = 1;
15 15
 }

+ 1
- 1
spec/faketime/faketime.h Datei anzeigen

@@ -1,2 +1,2 @@
1
-void freeze(unsigned long time);
1
+void _freeze(unsigned long time);
2 2
 void unfreeze();

BIN
spec/faketime/libfaketime.so Datei anzeigen


Laden…
Abbrechen
Speichern