-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
STEP-7 Code coverage added. #7
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Граф зависимостей – гуд.
- Схемы и их визуализация – гуд. В идеале опоясать их текстовыми пояснениями по моментам, описанным задании про документацию. Иначе полноценной документацией это назвать нельзя
- Приседания с jwt показались половинчатыми, как будто оставили работу на пол пути. Стоит доработать, или явно пояснить почему оставили в таком состоянии и к чему стремились.
2 из 3 норм – лайк. На Stepik также засчитываем модуль.
@@ -47,14 +46,12 @@ func (a access) HasRole(name string) bool { | |||
return false | |||
} | |||
|
|||
// Valid returns errors: | |||
// Validate checks validity of the claims (will be called by jwt-go library parser). | |||
// possible errors: | |||
// - from StandardClaims validation; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Комментарий к методу не соответствует действительности 🙂 Ошибок от StandardClaims больше нет
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Исправил
) | ||
|
||
type claims struct { | ||
jwt.StandardClaims | ||
Aud keycloakclient.Audition `json:"aud"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Можно теперь спилить и пользоваться зеркальным полем из jwt.RegisteredClaims
. У нас была специфическая нужда выделить отдельное поле из jwt.StandardClaims
, т.к. там aud строго строка
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Исправил
) | ||
|
||
type claims struct { | ||
jwt.StandardClaims | ||
Aud keycloakclient.Audition `json:"aud"` | ||
AuthTime int64 `json:"auth_time"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Раз уж начали глядеть сюда, то зачем вам это поле? Вроде, не используется 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Удалил
}, nil | ||
} | ||
|
||
// q: write documentation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Академический интерес: что значит q:
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Артифакт от общения с GitHub Copilot :)
issuer string `option:"mandatory" validate:"required"` | ||
} | ||
|
||
func NewJWTParser(opts JWTParserOptions) (*JWTParser, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
В keycloakclient
ещё есть код авторизации, который используется в тестах, так что удалил только то, что связано с интроспекцией токена.
Парсер перенёс в пакет internaljwt
.
# C4 model architecture diagrams | ||
|
||
## System Context | ||
<details> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Не знал, как в MD-формате делать раскрывающиеся списки. Лайк 🙂
Taskfile.yml
Outdated
@@ -8,6 +8,7 @@ vars: | |||
docker-compose.yml | |||
docker-compose.sentry.yml | |||
docker-compose.swagger-ui.yml | |||
docker-compose.structurizr.yml |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Опечатка у вас, нет такого файла 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Исправил.
# https://docs.structurizr.com/dsl/basics#basics | ||
# To see diagrams: | ||
# 1. Run dependencies COMPOSE_PROFILES=structurizr-ui task deps | ||
# 2. Open http://localhost:8070 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Прикольная штука – лайк 👍
Академический интерес: используете ли в работе? Поделитесь, пожалуйста, юзкейсами.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Пока только в этом проекте использовал.
internal/config/parse_test.go
Outdated
@@ -23,3 +25,11 @@ func TestParseAndValidate(t *testing.T) { | |||
require.NoError(t, err) | |||
assert.NotEmpty(t, cfg.Log.Level) | |||
} | |||
|
|||
func TestParseAndValidateWithEnv(t *testing.T) { | |||
assert.NoError(t, os.Setenv(fmt.Sprintf("%s_LOG_LEVEL", config.EnvPrefix), "debug")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Тут, скорее, нужен require
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Исправил.
internal/config/parse_test.go
Outdated
@@ -23,3 +25,11 @@ func TestParseAndValidate(t *testing.T) { | |||
require.NoError(t, err) | |||
assert.NotEmpty(t, cfg.Log.Level) | |||
} | |||
|
|||
func TestParseAndValidateWithEnv(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Скорее, это тест на переопределение ENV-переменной значения из конфига 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Переименовал тест.
Test renamed.
Task commands to run Swagger and Structurizr ui added.
JWT parser moved to package 'internaljwt'.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
По-прежнему лайк. Стало гораздо чище 🫡
BasePath string `fig:"base_path" validate:"required,url"` | ||
Realm string `fig:"realm" validate:"required"` | ||
ClientID string `fig:"client_id" validate:"required"` | ||
ClientSecret string `fig:"client_secret" validate:"required"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Вы правы, я сам это упустил это при ревью. Лайк 👍
} | ||
if err := c.Valid(); err != nil { | ||
return false, err | ||
// var ve *jwt.ValidationError |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
А тут какую цель преследовали, пытаясь анализировать содержимое ошибки? 🙂
Судя по тому, что тесты проходят в keycloak_token_auth_test.go
, ошибки из keycloak_claims.go
стали прозрачно возвращаться -> можно спилить закоментированный код
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Похожие артефакты как будто в func (s *KeycloakTokenAuthSuite) TestInvalidIssuer() {
authMdlwr echo.MiddlewareFunc | ||
req *http.Request | ||
resp *httptest.ResponseRecorder | ||
ctx echo.Context | ||
} | ||
|
||
func (s *KeycloakTokenAuthSuite) SetupTest() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Лайк за адаптацию теста 🫡
} | ||
token, c, err := parseTokenAndClaims(tokenStr) | ||
tokenStr := extractToken(auth, secWsProtocol) | ||
// if result, err := introspector.IntrospectToken(eCtx.Request().Context(), tokenStr); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Почти, осталось чуть-чуть подчистить, кмк 🙂
No description provided.