- Add comprehensive test file for internal/grpcserver package - Cover interceptors, system, engine, policy, and auth handlers - Cover pbToRule/ruleToPB conversion helpers - 37 tests total; CA/PKI/ACME and Login/Logout skipped (require live deps) Co-authored-by: Junie <junie@jetbrains.com>
31 lines
691 B
Go
31 lines
691 B
Go
package webserver
|
|
|
|
import (
|
|
"context"
|
|
"crypto/x509"
|
|
"encoding/pem"
|
|
"errors"
|
|
)
|
|
|
|
type contextKey int
|
|
|
|
const tokenInfoCtxKey contextKey = iota
|
|
|
|
func withTokenInfo(ctx context.Context, info *TokenInfo) context.Context {
|
|
return context.WithValue(ctx, tokenInfoCtxKey, info)
|
|
}
|
|
|
|
func tokenInfoFromContext(ctx context.Context) *TokenInfo {
|
|
v, _ := ctx.Value(tokenInfoCtxKey).(*TokenInfo)
|
|
return v
|
|
}
|
|
|
|
// parsePEMCert decodes the first PEM block and parses it as an x509 certificate.
|
|
func parsePEMCert(pemData []byte) (*x509.Certificate, error) {
|
|
block, _ := pem.Decode(pemData)
|
|
if block == nil {
|
|
return nil, errors.New("no PEM block found")
|
|
}
|
|
return x509.ParseCertificate(block.Bytes)
|
|
}
|