Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
asapo
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Joao Alvim Oliveira Dias De Almeida
asapo
Commits
db70a0e3
Commit
db70a0e3
authored
5 years ago
by
Sergey Yakubov
Browse files
Options
Downloads
Patches
Plain Diff
update authorize service for new format
parent
92620251
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
authorizer/src/asapo_authorizer/server/authorize.go
+21
-2
21 additions, 2 deletions
authorizer/src/asapo_authorizer/server/authorize.go
authorizer/src/asapo_authorizer/server/authorize_test.go
+30
-15
30 additions, 15 deletions
authorizer/src/asapo_authorizer/server/authorize_test.go
with
51 additions
and
17 deletions
authorizer/src/asapo_authorizer/server/authorize.go
+
21
−
2
View file @
db70a0e3
...
@@ -12,6 +12,7 @@ import (
...
@@ -12,6 +12,7 @@ import (
type
SourceCredentials
struct
{
type
SourceCredentials
struct
{
BeamtimeId
string
BeamtimeId
string
Beamline
string
Stream
string
Stream
string
Token
string
Token
string
}
}
...
@@ -24,13 +25,26 @@ type authorizationRequest struct {
...
@@ -24,13 +25,26 @@ type authorizationRequest struct {
func
getSourceCredentials
(
request
authorizationRequest
)
(
SourceCredentials
,
error
){
func
getSourceCredentials
(
request
authorizationRequest
)
(
SourceCredentials
,
error
){
vals
:=
strings
.
Split
(
request
.
SourceCredentials
,
"%"
)
vals
:=
strings
.
Split
(
request
.
SourceCredentials
,
"%"
)
if
len
(
vals
)
!=
3
{
if
len
(
vals
)
!=
4
{
return
SourceCredentials
{},
errors
.
New
(
"cannot get source credentials from "
+
request
.
SourceCredentials
)
return
SourceCredentials
{},
errors
.
New
(
"cannot get source credentials from "
+
request
.
SourceCredentials
)
}
}
creds
:=
SourceCredentials
{
vals
[
0
],
vals
[
1
],
vals
[
2
]}
creds
:=
SourceCredentials
{
vals
[
0
],
vals
[
1
],
vals
[
2
]
,
vals
[
3
]
}
if
creds
.
Stream
==
""
{
if
creds
.
Stream
==
""
{
creds
.
Stream
=
"detector"
creds
.
Stream
=
"detector"
}
}
if
creds
.
Beamline
==
""
{
creds
.
Beamline
=
"auto"
}
if
creds
.
BeamtimeId
==
""
{
creds
.
BeamtimeId
=
"auto"
}
if
creds
.
BeamtimeId
==
"auto"
&&
creds
.
Beamline
==
"auto"
{
return
SourceCredentials
{},
errors
.
New
(
"cannot automaticaly detect both beamline and beamtime_id "
)
}
return
creds
,
nil
return
creds
,
nil
}
}
...
@@ -158,6 +172,11 @@ func authorize(request authorizationRequest,creds SourceCredentials) (beamtimeIn
...
@@ -158,6 +172,11 @@ func authorize(request authorizationRequest,creds SourceCredentials) (beamtimeIn
}
}
}
}
if
creds
.
Beamline
!=
"auto"
&&
beamlineInfo
.
Beamline
!=
creds
.
Beamline
{
log
.
Debug
(
"given beamline ("
+
creds
.
Beamline
+
") does not match the found one ("
+
beamlineInfo
.
Beamline
+
")"
)
return
beamtimeInfo
{},
false
}
var
answer
beamtimeInfo
var
answer
beamtimeInfo
answer
.
Beamline
=
beamlineInfo
.
Beamline
answer
.
Beamline
=
beamlineInfo
.
Beamline
answer
.
Facility
=
beamlineInfo
.
Facility
answer
.
Facility
=
beamlineInfo
.
Facility
...
...
This diff is collapsed.
Click to expand it.
authorizer/src/asapo_authorizer/server/authorize_test.go
+
30
−
15
View file @
db70a0e3
...
@@ -52,12 +52,19 @@ func doAuthorizeRequest(path string,buf string) *httptest.ResponseRecorder {
...
@@ -52,12 +52,19 @@ func doAuthorizeRequest(path string,buf string) *httptest.ResponseRecorder {
var
credTests
=
[]
struct
{
var
credTests
=
[]
struct
{
request
string
request
string
cred
SourceCredentials
cred
SourceCredentials
ok
bool
message
string
message
string
}
{
}
{
{
"asapo_test%%"
,
SourceCredentials
{
"asapo_test"
,
"detector"
,
""
},
"default stream and no token"
},
{
"asapo_test%auto%%"
,
SourceCredentials
{
"asapo_test"
,
"auto"
,
"detector"
,
""
},
true
,
"auto beamline, stream and no token"
},
{
"asapo_test%%token"
,
SourceCredentials
{
"asapo_test"
,
"detector"
,
"token"
},
"default stream"
},
{
"asapo_test%auto%%token"
,
SourceCredentials
{
"asapo_test"
,
"auto"
,
"detector"
,
"token"
},
true
,
"auto beamline, stream"
},
{
"asapo_test%stream%"
,
SourceCredentials
{
"asapo_test"
,
"stream"
,
""
},
"no token"
},
{
"asapo_test%auto%stream%"
,
SourceCredentials
{
"asapo_test"
,
"auto"
,
"stream"
,
""
},
true
,
"auto beamline, no token"
},
{
"asapo_test%stream%token"
,
SourceCredentials
{
"asapo_test"
,
"stream"
,
"token"
},
"all set"
},
{
"asapo_test%auto%stream%token"
,
SourceCredentials
{
"asapo_test"
,
"auto"
,
"stream"
,
"token"
},
true
,
"auto beamline,stream, token"
},
{
"asapo_test%beamline%stream%token"
,
SourceCredentials
{
"asapo_test"
,
"beamline"
,
"stream"
,
"token"
},
true
,
"all set"
},
{
"auto%beamline%stream%token"
,
SourceCredentials
{
"auto"
,
"beamline"
,
"stream"
,
"token"
},
true
,
"auto beamtime"
},
{
"auto%auto%stream%token"
,
SourceCredentials
{},
false
,
"auto beamtime and beamline"
},
{
"%beamline%stream%token"
,
SourceCredentials
{
"auto"
,
"beamline"
,
"stream"
,
"token"
},
true
,
"empty beamtime"
},
{
"asapo_test%%stream%token"
,
SourceCredentials
{
"asapo_test"
,
"auto"
,
"stream"
,
"token"
},
true
,
"empty bealine"
},
{
"%%stream%token"
,
SourceCredentials
{},
false
,
"both empty"
},
}
}
func
TestSplitCreds
(
t
*
testing
.
T
)
{
func
TestSplitCreds
(
t
*
testing
.
T
)
{
...
@@ -65,14 +72,19 @@ func TestSplitCreds(t *testing.T) {
...
@@ -65,14 +72,19 @@ func TestSplitCreds(t *testing.T) {
for
_
,
test
:=
range
credTests
{
for
_
,
test
:=
range
credTests
{
request
:=
authorizationRequest
{
test
.
request
,
"host"
}
request
:=
authorizationRequest
{
test
.
request
,
"host"
}
creds
,
err
:=
getSourceCredentials
(
request
)
creds
,
err
:=
getSourceCredentials
(
request
)
assert
.
Nil
(
t
,
err
)
if
test
.
ok
{
assert
.
Equal
(
t
,
creds
,
test
.
cred
,
test
.
message
)
assert
.
Nil
(
t
,
err
)
assert
.
Equal
(
t
,
creds
,
test
.
cred
,
test
.
message
)
}
else
{
assert
.
NotNil
(
t
,
err
,
test
.
message
)
}
}
}
}
}
func
TestAuthorizeDefaultOK
(
t
*
testing
.
T
)
{
func
TestAuthorizeDefaultOK
(
t
*
testing
.
T
)
{
allowBeamlines
([]
beamtimeInfo
{{
"asapo_test"
,
"beamline"
,
""
,
"2019"
,
"tf"
}})
allowBeamlines
([]
beamtimeInfo
{{
"asapo_test"
,
"beamline"
,
""
,
"2019"
,
"tf"
}})
request
:=
makeRequest
(
authorizationRequest
{
"asapo_test%%"
,
"host"
})
request
:=
makeRequest
(
authorizationRequest
{
"asapo_test%%
%
"
,
"host"
})
w
:=
doAuthorizeRequest
(
"/authorize"
,
request
)
w
:=
doAuthorizeRequest
(
"/authorize"
,
request
)
body
,
_
:=
ioutil
.
ReadAll
(
w
.
Body
)
body
,
_
:=
ioutil
.
ReadAll
(
w
.
Body
)
...
@@ -86,15 +98,18 @@ func TestAuthorizeDefaultOK(t *testing.T) {
...
@@ -86,15 +98,18 @@ func TestAuthorizeDefaultOK(t *testing.T) {
var
authTests
=
[]
struct
{
var
authTests
=
[]
struct
{
beamtime_id
string
beamtime_id
string
beamline
string
stream
string
stream
string
token
string
token
string
status
int
status
int
message
string
message
string
}{
}{
{
"test"
,
"stream"
,
prepareToken
(
"test"
),
http
.
StatusOK
,
"user stream with correct token"
},
{
"test"
,
"auto"
,
"stream"
,
prepareToken
(
"test"
),
http
.
StatusOK
,
"user stream with correct token"
},
{
"test1"
,
"stream"
,
prepareToken
(
"test1"
),
http
.
StatusUnauthorized
,
"correct token, beamtime not found"
},
{
"test1"
,
"auto"
,
"stream"
,
prepareToken
(
"test1"
),
http
.
StatusUnauthorized
,
"correct token, beamtime not found"
},
{
"test"
,
"stream"
,
prepareToken
(
"wrong"
),
http
.
StatusUnauthorized
,
"user stream with wrong token"
},
{
"test"
,
"auto"
,
"stream"
,
prepareToken
(
"wrong"
),
http
.
StatusUnauthorized
,
"user stream with wrong token"
},
{
"test"
,
"detector_aaa"
,
prepareToken
(
"test"
),
http
.
StatusUnauthorized
,
"detector stream with correct token and wroung source"
},
{
"test"
,
"auto"
,
"detector_aaa"
,
prepareToken
(
"test"
),
http
.
StatusUnauthorized
,
"detector stream with correct token and wroung source"
},
{
"test"
,
"bl1"
,
"stream"
,
prepareToken
(
"test"
),
http
.
StatusOK
,
"correct beamline given"
},
{
"test"
,
"bl2"
,
"stream"
,
prepareToken
(
"test"
),
http
.
StatusUnauthorized
,
"incorrect beamline given"
},
}
}
func
TestAuthorizeWithToken
(
t
*
testing
.
T
)
{
func
TestAuthorizeWithToken
(
t
*
testing
.
T
)
{
allowBeamlines
([]
beamtimeInfo
{})
allowBeamlines
([]
beamtimeInfo
{})
...
@@ -103,7 +118,7 @@ func TestAuthorizeWithToken(t *testing.T) {
...
@@ -103,7 +118,7 @@ func TestAuthorizeWithToken(t *testing.T) {
defer
os
.
RemoveAll
(
"tf"
)
defer
os
.
RemoveAll
(
"tf"
)
for
_
,
test
:=
range
authTests
{
for
_
,
test
:=
range
authTests
{
request
:=
makeRequest
(
authorizationRequest
{
test
.
beamtime_id
+
"%"
+
test
.
stream
+
"%"
+
test
.
token
,
"host"
})
request
:=
makeRequest
(
authorizationRequest
{
test
.
beamtime_id
+
"%"
+
test
.
beamline
+
"%"
+
test
.
stream
+
"%"
+
test
.
token
,
"host"
})
w
:=
doAuthorizeRequest
(
"/authorize"
,
request
)
w
:=
doAuthorizeRequest
(
"/authorize"
,
request
)
body
,
_
:=
ioutil
.
ReadAll
(
w
.
Body
)
body
,
_
:=
ioutil
.
ReadAll
(
w
.
Body
)
...
@@ -125,7 +140,7 @@ func TestAuthorizeWithToken(t *testing.T) {
...
@@ -125,7 +140,7 @@ func TestAuthorizeWithToken(t *testing.T) {
func
TestNotAuthorized
(
t
*
testing
.
T
)
{
func
TestNotAuthorized
(
t
*
testing
.
T
)
{
request
:=
makeRequest
(
authorizationRequest
{
"any_id%%"
,
"host"
})
request
:=
makeRequest
(
authorizationRequest
{
"any_id%%
%
"
,
"host"
})
w
:=
doAuthorizeRequest
(
"/authorize"
,
request
)
w
:=
doAuthorizeRequest
(
"/authorize"
,
request
)
assert
.
Equal
(
t
,
http
.
StatusUnauthorized
,
w
.
Code
,
""
)
assert
.
Equal
(
t
,
http
.
StatusUnauthorized
,
w
.
Code
,
""
)
}
}
...
@@ -178,7 +193,7 @@ func TestAuthorizeWithFile(t *testing.T) {
...
@@ -178,7 +193,7 @@ func TestAuthorizeWithFile(t *testing.T) {
ioutil
.
WriteFile
(
"127.0.0.1"
,
[]
byte
(
"bl1"
),
0644
)
ioutil
.
WriteFile
(
"127.0.0.1"
,
[]
byte
(
"bl1"
),
0644
)
request
:=
authorizationRequest
{
"11003924%%"
,
"127.0.0.1"
}
request
:=
authorizationRequest
{
"11003924%%
%
"
,
"127.0.0.1"
}
w
:=
doAuthorizeRequest
(
"/authorize"
,
makeRequest
(
request
))
w
:=
doAuthorizeRequest
(
"/authorize"
,
makeRequest
(
request
))
body
,
_
:=
ioutil
.
ReadAll
(
w
.
Body
)
body
,
_
:=
ioutil
.
ReadAll
(
w
.
Body
)
...
@@ -189,7 +204,7 @@ func TestAuthorizeWithFile(t *testing.T) {
...
@@ -189,7 +204,7 @@ func TestAuthorizeWithFile(t *testing.T) {
assert
.
Contains
(
t
,
string
(
body
),
"tf"
,
""
)
assert
.
Contains
(
t
,
string
(
body
),
"tf"
,
""
)
assert
.
Equal
(
t
,
http
.
StatusOK
,
w
.
Code
,
""
)
assert
.
Equal
(
t
,
http
.
StatusOK
,
w
.
Code
,
""
)
request
=
authorizationRequest
{
"wrong%%"
,
"127.0.0.1"
}
request
=
authorizationRequest
{
"wrong%%
%
"
,
"127.0.0.1"
}
w
=
doAuthorizeRequest
(
"/authorize"
,
makeRequest
(
request
))
w
=
doAuthorizeRequest
(
"/authorize"
,
makeRequest
(
request
))
assert
.
Equal
(
t
,
http
.
StatusUnauthorized
,
w
.
Code
,
""
)
assert
.
Equal
(
t
,
http
.
StatusUnauthorized
,
w
.
Code
,
""
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment