opentofu 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +5 -10
- data/CHANGELOG.md +19 -1
- data/lib/net/tofu/error.rb +3 -0
- data/lib/net/tofu/request.rb +10 -52
- data/lib/net/tofu/response.rb +14 -4
- data/lib/net/tofu/version.rb +4 -2
- data/lib/uri/gemini.rb +3 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a69c67e3a0d558a57695eafff1a69d111d8ff7ccc6c74de393efe6cb5f0bf276
|
4
|
+
data.tar.gz: 780851bb7b0166ec9ea945f71735eba1c795cd399a7633606bdd4639762c6b59
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c506b5667e6e99e717f0455c94a6e362664a5c299d880f465b031aa684969120c5484175c28606fc5aaabc39bd1fa577c89f6d05374e1df8ea37642dd4bf91e3
|
7
|
+
data.tar.gz: 5d6f6f2ea96f1ea01a5b442dba6f1f8ef8f83f40f852866b28995fcd879a96a6914030f20303a71d6c9b21e2a56346aba28ad74b9a03a832a71b34e57325a1c2
|
data/.rubocop.yml
CHANGED
@@ -1,16 +1,13 @@
|
|
1
1
|
AllCops:
|
2
2
|
TargetRubyVersion: 2.6
|
3
3
|
|
4
|
-
Metrics/
|
4
|
+
Metrics/AbcSize:
|
5
5
|
Enabled: true
|
6
|
-
Max:
|
7
|
-
Exclude:
|
8
|
-
- "lib/net/tofu/response.rb"
|
6
|
+
Max: 25
|
9
7
|
|
10
|
-
|
8
|
+
Metrics/MethodLength:
|
11
9
|
Enabled: true
|
12
|
-
|
13
|
-
- "lib/net/tofu/request.rb"
|
10
|
+
Max: 18
|
14
11
|
|
15
12
|
Style/Semicolon:
|
16
13
|
Enabled: true
|
@@ -18,9 +15,7 @@ Style/Semicolon:
|
|
18
15
|
- "lib/net/tofu/response.rb"
|
19
16
|
|
20
17
|
Style/SingleLineMethods:
|
21
|
-
Enabled:
|
22
|
-
Exclude:
|
23
|
-
- "lib/net/tofu/response.rb"
|
18
|
+
Enabled: false
|
24
19
|
|
25
20
|
Style/StringLiterals:
|
26
21
|
Enabled: true
|
data/CHANGELOG.md
CHANGED
@@ -5,7 +5,25 @@ All notable changes to this project will be documented in this file.
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
7
7
|
|
8
|
-
## [0.1.
|
8
|
+
## [0.1.1] - 2023-07-28
|
9
|
+
|
10
|
+
### Added
|
11
|
+
|
12
|
+
- Tests.
|
13
|
+
- The `simplecov` gem to view testing coverage.
|
14
|
+
- A new error, for if the server doesn't send any data.
|
15
|
+
- The Linux platform to the bundle platform.
|
16
|
+
|
17
|
+
### Fixed
|
18
|
+
|
19
|
+
- Complexity issues in the Response class from the linter.
|
20
|
+
|
21
|
+
### Removed
|
22
|
+
|
23
|
+
- The `@@current_host` class variable from Request. Clients should handle keeping track of the current host, Tofu should just fetch data.
|
24
|
+
- The complicated logic used to parse host names from the Request class, as per the above point.
|
25
|
+
|
26
|
+
## [0.1.0] - 2023-07-27
|
9
27
|
|
10
28
|
First release. Still lots of improvements to be made.
|
11
29
|
|
data/lib/net/tofu/error.rb
CHANGED
data/lib/net/tofu/request.rb
CHANGED
@@ -4,8 +4,6 @@ module Net
|
|
4
4
|
module Tofu
|
5
5
|
# Stores a client request to a Gemini server.
|
6
6
|
class Request
|
7
|
-
SCHEME = "gemini"
|
8
|
-
|
9
7
|
MAX_URI_BYTESIZE = 1024
|
10
8
|
|
11
9
|
# @return [URI] The full URI object of the request.
|
@@ -36,17 +34,12 @@ module Net
|
|
36
34
|
# @param host [String] A host string, optionally with the gemini:// scheme.
|
37
35
|
# @param port [Integer] Optional parameter to specify the server port to connect to.
|
38
36
|
def initialize(host, port: nil)
|
39
|
-
|
40
|
-
|
37
|
+
@uri = URI(host)
|
38
|
+
@uri.port = port unless port.nil?
|
41
39
|
|
42
|
-
@host = host
|
43
|
-
@port = port unless port.nil?
|
44
|
-
determine_host
|
45
40
|
parse_head
|
46
41
|
parse_tail
|
47
42
|
|
48
|
-
puts format
|
49
|
-
|
50
43
|
# Make sure the URI isn't too large
|
51
44
|
if format.bytesize > MAX_URI_BYTESIZE
|
52
45
|
raise InvalidURIError,
|
@@ -73,63 +66,28 @@ module Net
|
|
73
66
|
|
74
67
|
private
|
75
68
|
|
76
|
-
# Parses the host and the path, and sets the current_host.
|
77
|
-
def determine_host
|
78
|
-
puts "current: #{@@current_host}"
|
79
|
-
@uri = URI(@host)
|
80
|
-
|
81
|
-
unless @uri.host.nil? || @uri.host.empty?
|
82
|
-
@host = @uri.host
|
83
|
-
@@current_host = @host
|
84
|
-
return
|
85
|
-
end
|
86
|
-
|
87
|
-
return if @uri.path.nil? || @uri.path.empty?
|
88
|
-
return unless @uri.host.nil? || @uri.host.empty?
|
89
|
-
|
90
|
-
if @uri.path.start_with?("/")
|
91
|
-
raise InvalidURIError, "No host specified" if @@current_host.nil? || @@current_host.empty?
|
92
|
-
|
93
|
-
unless @@current_host.nil? || @@current_host.empty?
|
94
|
-
@uri.host = @@current_host
|
95
|
-
@host = @uri.host
|
96
|
-
@@current_host = @host
|
97
|
-
end
|
98
|
-
|
99
|
-
return
|
100
|
-
end
|
101
|
-
|
102
|
-
paths = @uri.path.split("/")
|
103
|
-
puts paths
|
104
|
-
|
105
|
-
@uri.host = paths[0]
|
106
|
-
@host = @uri.host
|
107
|
-
@@current_host = @host
|
108
|
-
@uri.path = nil if paths.length == 1
|
109
|
-
return unless paths.length > 1
|
110
|
-
|
111
|
-
@uri.path = paths[1..].join("/")
|
112
|
-
@uri.path = "/#{uri.path}"
|
113
|
-
end
|
114
|
-
|
115
69
|
# Parses the scheme, the host, and the port for the request.
|
116
70
|
def parse_head
|
117
71
|
# Check if a scheme was specified, if not, default to gemini://
|
118
72
|
# Also set the port if this happens
|
119
73
|
if @uri.scheme.nil? || @uri.scheme.empty?
|
120
|
-
@uri.scheme =
|
121
|
-
@uri.port = URI::Gemini::DEFAULT_PORT
|
74
|
+
@uri.scheme = URI::Gemini::DEFAULT_SCHEME
|
75
|
+
@uri.port = URI::Gemini::DEFAULT_PORT if @uri.port.nil?
|
122
76
|
end
|
123
77
|
|
78
|
+
# Check if a host was specified.
|
79
|
+
raise InvalidURIError, "Request does not contain a host" if @uri.host.nil? || @uri.host.empty?
|
80
|
+
|
124
81
|
# Set member parts
|
125
82
|
@scheme = @uri.scheme
|
83
|
+
@host = @uri.host
|
126
84
|
@port = @uri.port
|
127
85
|
|
128
86
|
# Check if a scheme is present that isn't gemini://
|
129
|
-
return if @uri.scheme ==
|
87
|
+
return if @uri.scheme == URI::Gemini::DEFAULT_SCHEME
|
130
88
|
|
131
89
|
raise InvalidSchemeError,
|
132
|
-
"Request uses an invalid scheme (has: #{@uri.scheme}, wants: #{
|
90
|
+
"Request uses an invalid scheme (has: #{@uri.scheme}, wants: #{URI::Gemini::DEFAULT_SCHEME}"
|
133
91
|
end
|
134
92
|
|
135
93
|
# Parses the path, the query, and the fragment for the request.
|
data/lib/net/tofu/response.rb
CHANGED
@@ -83,6 +83,8 @@ module Net
|
|
83
83
|
|
84
84
|
# Splits up the responseinto a header and a body.
|
85
85
|
def parse
|
86
|
+
raise NoServerResponseError if @data.nil? || @data.empty?
|
87
|
+
|
86
88
|
# Extract the header and parse it
|
87
89
|
a = @data.split("\n")
|
88
90
|
@header = a[0].strip
|
@@ -108,6 +110,7 @@ module Net
|
|
108
110
|
# Parse the meta
|
109
111
|
@meta = ""
|
110
112
|
@meta = a[1..].join(" ") if a.length >= 2
|
113
|
+
@meta.strip!
|
111
114
|
parse_meta
|
112
115
|
end
|
113
116
|
|
@@ -144,14 +147,21 @@ module Net
|
|
144
147
|
def parse_meta
|
145
148
|
# Make sure the meta isn't too large
|
146
149
|
if @meta.bytesize > MAX_META_BYTESIZE
|
147
|
-
raise InvalidMetaError,
|
148
|
-
|
150
|
+
raise InvalidMetaError, <<-TXT
|
151
|
+
The server sent a meta that was too large, should be #{MAX_META_BYTESIZE} bytes,
|
152
|
+
instead is #{@meta.bytesize} bytes
|
153
|
+
TXT
|
149
154
|
end
|
150
155
|
|
151
156
|
if @status_maj == TEMPORARY_FAILURE || @status_maj == PERMANENT_FAILURE || @status_maj == REQUEST_CERTIFICATE
|
152
157
|
return
|
153
158
|
end
|
154
159
|
|
160
|
+
# Handle extra checks based on the @status type
|
161
|
+
handle_type
|
162
|
+
end
|
163
|
+
|
164
|
+
def handle_type
|
155
165
|
# Make sure meta exists (i.e. has length)
|
156
166
|
# This satisfies the INPUT and SUCCESS
|
157
167
|
unless @meta.length.positive?
|
@@ -169,10 +179,10 @@ module Net
|
|
169
179
|
raise InvalidRedirectError, "The redirect link does not have a scheme" if uri.scheme.nil? || uri.scheme.empty?
|
170
180
|
|
171
181
|
# Make sure the URI scheme is 'gemini'
|
172
|
-
return if uri.scheme ==
|
182
|
+
return if uri.scheme == URI::Gemini::DEFAULT_SCHEME
|
173
183
|
|
174
184
|
raise InvalidRedirectError,
|
175
|
-
"The redirect link has an invalid scheme (has: #{uri.scheme}, wants:
|
185
|
+
"The redirect link has an invalid scheme (has: #{uri.scheme}, wants: #{URI::Gemini::DEFAULT_SCHEME})"
|
176
186
|
end
|
177
187
|
end
|
178
188
|
end
|
data/lib/net/tofu/version.rb
CHANGED
data/lib/uri/gemini.rb
CHANGED
@@ -35,6 +35,9 @@ module URI # :nodoc:
|
|
35
35
|
# A Default port of 1965 for URI::Gemini.
|
36
36
|
DEFAULT_PORT = 1965
|
37
37
|
|
38
|
+
# A Default scheme of gemini for URI::Gemini.
|
39
|
+
DEFAULT_SCHEME = "gemini"
|
40
|
+
|
38
41
|
# An Array of the available components for URI::Gemini.
|
39
42
|
COMPONENT = %i[scheme host port
|
40
43
|
path query fragment].freeze
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: opentofu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rory Dudley
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-07-
|
11
|
+
date: 2023-07-29 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |2
|
14
14
|
OpenTOFU is a client and certificate pinning library for Geminispace, derived from
|
@@ -39,7 +39,7 @@ metadata:
|
|
39
39
|
allowed_push_host: https://rubygems.org
|
40
40
|
homepage_uri: https://github.com/pinecat/opentofu
|
41
41
|
source_code_uri: https://github.com/pinecat/opentofu
|
42
|
-
changelog_uri: https://github.com/pinecat/opentofu
|
42
|
+
changelog_uri: https://github.com/pinecat/opentofu/blob/master/CHANGELOG.md
|
43
43
|
post_install_message:
|
44
44
|
rdoc_options: []
|
45
45
|
require_paths:
|