Skip to content

Commit

Permalink
Move most of omegaup-update-problem's functionality to gitserver
Browse files Browse the repository at this point in the history
This change is a huge refactor so that gitserver has all the
functionality that used to belong to omegaup-update-problem. Now the
protocol should be complete and the frontend should be able to stop
assuming that it is hosted in the same filesystem as the grader.
  • Loading branch information
lhchavez committed Jan 7, 2019
1 parent dee4244 commit 9e9f904
Show file tree
Hide file tree
Showing 7 changed files with 1,076 additions and 716 deletions.
8 changes: 7 additions & 1 deletion cmd/omegaup-gitserver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var (
pprofPort = flag.Int("pprof-port", 33862, "Port in which the pprof server will listen")
libinteractivePath = flag.String("libinteractive-path", "/usr/share/java/libinteractive.jar", "Path of libinteractive.jar")
allowDirectPushToMaster = flag.Bool("allow-direct-push-to-master", false, "Allow direct push to master")
verbose = flag.Bool("verbose", false, "Verbose logging")
log log15.Logger
)

Expand Down Expand Up @@ -141,7 +142,12 @@ func (h *muxGitHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {

func main() {
flag.Parse()
log = base.StderrLog()
if *verbose {
log = base.StderrLog()
} else {
log = log15.New()
log.SetHandler(base.ErrorCallerStackHandler(log15.LvlInfo, log15.StderrHandler))
}

stopChan := make(chan os.Signal)
signal.Notify(stopChan, os.Interrupt)
Expand Down
30 changes: 30 additions & 0 deletions cmd/omegaup-gitserver/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package main

import (
"encoding/base64"
"fmt"
base "github.com/omegaup/go-base"
"golang.org/x/crypto/ed25519"
"testing"
)

const (
expiredToken = "v2.public.eyJwcm9ibGVtIjoiYTA5NGY3MWI0ZmEzZmY4YmVhZmY0MDZiNTQ1YTU1NzgiLCJleHAiOiIyMDE5LTAxLTA0VDA1OjAzOjA0KzAwOjAwIiwiaXNzIjoib21lZ2FVcCBmcm9udGVuZCIsInN1YiI6IjBiOGJhM2FjN2M2MzVkM2U2OTg5MWU4ODAzYzc4YTJmIn0VXEbZ414QQ7qEY9MFa2gGgeJqc-T1Ff7fPM3ZQ_YQudq5I05offZxG819gmdmq3Z1_HeV7bjMRWL5JIkfkHIK"
)

func TestParseBearerAuth(t *testing.T) {
log := base.StderrLog()
keyBytes, err := base64.StdEncoding.DecodeString(*publicKeyBase64)
if err != nil {
t.Fatalf("failed to parse shared key: %v", err)
}
auth := bearerAuthorization{
log: log,
publicKey: ed25519.PublicKey(keyBytes),
}

_, _, ok := auth.parseBearerAuth(fmt.Sprintf("Bearer %s", expiredToken))
if ok {
t.Errorf("expired token was passed as valid")
}
}
2 changes: 1 addition & 1 deletion cmd/omegaup-migrate-problem/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ func convertCommitToPackfile(
return gitserver.CreatePackfile(
contents,
settings,
gitserver.ConvertZipUpdateAll,
gitserver.ZipMergeStrategyTheirs,
newRepo,
parentID,
originalCommit.Author(),
Expand Down
Loading

0 comments on commit 9e9f904

Please sign in to comment.