blob: cfb2d1a1bca9c00035cfbc563b458a2607b21d1f (
plain)
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
# frozen_string_literal: true
require 'date'
module QA
module Resource
class GroupAccessToken < Base
attr_writer :name
attribute :id
attribute :user_id
attribute :expires_at
attribute :token
attribute :group do
Group.fabricate!
end
def api_get_path
"/groups/#{group.id}/access_tokens/#{id}"
rescue NoValueError
token = parse_body(api_get_from("/groups/#{group.id}/access_tokens")).find { |t| t[:name] == name }
raise ResourceNotFoundError unless token
@id = token[:id]
retry
end
def identifier
"with name '#{name}', token's bot username '#{token_user[:username]}'"
end
def api_post_path
"/groups/#{group.id}/access_tokens"
end
def api_user_path
"/users/#{user_id}"
end
def token_user
parse_body(api_get_from(api_user_path))
end
def name
@name ||= "api-group-access-token-#{Faker::Alphanumeric.alphanumeric(number: 8)}"
end
def api_post_body
{
name: name,
scopes: ["api"],
expires_at: expires_at.to_s
}
end
def api_delete_path
"/groups/#{group.id}/access_tokens/#{id}"
end
def resource_web_url(resource)
super
rescue ResourceURLMissingError
# this particular resource does not expose a web_url property
end
def revoke_via_ui!
Page::Group::Settings::AccessTokens.perform do |tokens_page|
tokens_page.revoke_first_token_with_name(name)
end
end
# Expire in 2 days just in case the token is created just before midnight
def expires_at
@expires_at || Time.now.utc.to_date + 2
end
def fabricate!
Flow::Login.sign_in_unless_signed_in
group.visit!
Page::Group::Menu.perform(&:go_to_access_token_settings)
Page::Group::Settings::AccessTokens.perform do |token_page|
token_page.click_add_new_token_button
token_page.fill_token_name(name)
token_page.check_api
token_page.fill_expiry_date(expires_at)
token_page.click_create_token_button
self.token = token_page.created_access_token
end
reload!
end
end
end
end
|