File: authorization.rb

package info (click to toggle)
ruby-protocol-http 0.59.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 864 kB
  • sloc: ruby: 7,612; makefile: 4
file content (39 lines) | stat: -rw-r--r-- 990 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2019-2025, by Samuel Williams.

require "protocol/http/header/authorization"
require "protocol/http/headers"

describe Protocol::HTTP::Header::Authorization do
	with "basic username/password" do
		let(:header) {subject.basic("samuel", "password")}
		
		it "should generate correct authorization header" do
			expect(header).to be == "Basic c2FtdWVsOnBhc3N3b3Jk"
		end
		
		with "#credentials" do
			it "can split credentials" do
				expect(header.credentials).to be == ["Basic", "c2FtdWVsOnBhc3N3b3Jk"]
			end
		end
	end
	
	with ".parse" do
		it "parses raw authorization value" do
			result = subject.parse("Bearer token123")
			expect(result).to be_a(subject)
			expect(result).to be == "Bearer token123"
		end
	end
	
	with ".coerce" do
		it "coerces string to Authorization" do
			result = subject.coerce("Bearer xyz")
			expect(result).to be_a(subject)
			expect(result).to be == "Bearer xyz"
		end
	end
end