mirror of
https://github.com/documize/community.git
synced 2025-08-08 06:55:28 +02:00
Merge pull request #8 from documize/pre-release-tidy
Salt a param + pre-release tidy
This commit is contained in:
commit
20815494f0
6 changed files with 68 additions and 27 deletions
14
README.md
14
README.md
|
@ -12,17 +12,25 @@ You can operate outside the AGPL restrictions by purchasing Documize Enterprise
|
|||
|
||||
## Running Documize for the first time
|
||||
|
||||
Although the Documize binaries run on Linux, Windows and OSX, the build process has only been tested on OSX.
|
||||
Although the Documize binaries run on Linux, Windows and macOS, the build process has only been tested on macOS.
|
||||
|
||||
Install the prerequisites:
|
||||
* Go from https://golang.org (be careful to set the $GOPATH environment variable correctly, you may find https://www.goinggo.net/2016/05/installing-go-and-your-workspace.html helpful)
|
||||
* NPM from https://www.npmjs.com
|
||||
* Ember from http://emberjs.com/
|
||||
* MySQL (v10.7+) from http://dev.mysql.com/downloads/mysql/
|
||||
* Bower from https://bower.io/
|
||||
* MySQL (v10.7+) from http://dev.mysql.com/downloads/mysql/ (don't forget to copy the one-time password and your system may require a restart)
|
||||
|
||||
Make sure this repository sits at the following position relative to your $GOPATH: $GOPATH/src/github.com/documize/community
|
||||
|
||||
After cloning the repository in the above location, go there and run: ./build.sh
|
||||
After cloning the repository in the above location, go there and run:
|
||||
```
|
||||
cd app
|
||||
npm install
|
||||
bower install
|
||||
cd ..
|
||||
./build.sh
|
||||
```
|
||||
|
||||
The build script packages up the Ember JS/HTML/CSS code for production use, then generates Go code that creates a simple in-memory file system to contain it. That generated Go code is compiled with the rest to produce a single binary for each of the target systems.
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
package endpoint
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
|
@ -21,11 +22,13 @@ import (
|
|||
"time"
|
||||
|
||||
jwt "github.com/dgrijalva/jwt-go"
|
||||
|
||||
"github.com/documize/community/documize/api/endpoint/models"
|
||||
"github.com/documize/community/documize/api/entity"
|
||||
"github.com/documize/community/documize/api/request"
|
||||
"github.com/documize/community/documize/api/util"
|
||||
"github.com/documize/community/documize/section/provider"
|
||||
"github.com/documize/community/wordsmith/environment"
|
||||
"github.com/documize/community/wordsmith/log"
|
||||
"github.com/documize/community/wordsmith/utility"
|
||||
)
|
||||
|
@ -298,7 +301,33 @@ func preAuthorizeStaticAssets(r *http.Request) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
const jwtKey = "tsu3Acndky8cdTNx3"
|
||||
var jwtKey string
|
||||
|
||||
func init() {
|
||||
environment.GetString(&jwtKey, "salt", false, "the salt string used to encode JWT tokens, if not set a random value will be generated",
|
||||
func(t *string, n string) bool {
|
||||
if jwtKey == "" {
|
||||
b := make([]byte, 17)
|
||||
_, err := rand.Read(b)
|
||||
if err != nil {
|
||||
jwtKey = err.Error()
|
||||
log.Error("problem using crypto/rand", err)
|
||||
return false
|
||||
}
|
||||
for k, v := range b {
|
||||
if (v >= 'a' && v <= 'z') || (v >= 'A' && v <= 'Z') || (v >= '0' && v <= '0') {
|
||||
b[k] = v
|
||||
} else {
|
||||
s := fmt.Sprintf("%x", v)
|
||||
b[k] = s[0]
|
||||
}
|
||||
}
|
||||
jwtKey = string(b)
|
||||
log.Info("Please set DOCUMIZESALT or use -salt with this value: " + jwtKey)
|
||||
}
|
||||
return true
|
||||
})
|
||||
}
|
||||
|
||||
// Generates JSON Web Token (http://jwt.io)
|
||||
func generateJWT(user, org, domain string) string {
|
||||
|
|
|
@ -712,7 +712,8 @@ func writeUsers(w http.ResponseWriter, u []entity.User) {
|
|||
|
||||
if err != nil {
|
||||
log.Error("unable to writeUsers", err)
|
||||
u = []entity.User{}
|
||||
writeServerError(w, "unabe to writeUsers", err)
|
||||
return
|
||||
}
|
||||
|
||||
writeSuccessBytes(w, j)
|
||||
|
|
|
@ -102,19 +102,19 @@ func TestOrganization(t *testing.T) {
|
|||
|
||||
_, err = p.GetOrganization("XXXXXXXXX")
|
||||
if err == nil {
|
||||
t.Error("no error getting non-existant organization", err)
|
||||
t.Error("no error getting non-existent organization", err)
|
||||
}
|
||||
p.testRollback(t)
|
||||
|
||||
err = p.UpdateOrganization(entity.Organization{BaseEntity: entity.BaseEntity{RefID: "XXXXXXXXX"}})
|
||||
if err == nil {
|
||||
t.Error("no error updating non-existant organization", err)
|
||||
t.Error("no error updating non-existent organization", err)
|
||||
}
|
||||
p.testRollback(t)
|
||||
|
||||
err = p.RemoveOrganization("XXXXXXXXX")
|
||||
if err == nil {
|
||||
t.Error("no error removing non-existant organization", err)
|
||||
t.Error("no error removing non-existent organization", err)
|
||||
}
|
||||
p.testRollback(t)
|
||||
}
|
||||
|
|
|
@ -14,24 +14,26 @@ package section
|
|||
import (
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"github.com/documize/community/documize/section/provider"
|
||||
)
|
||||
|
||||
type testsection struct {
|
||||
didRefresh bool
|
||||
}
|
||||
type testsection provider.TypeMeta
|
||||
|
||||
var ts testsection
|
||||
|
||||
func init() {
|
||||
sectionsMap["testsection"] = &ts
|
||||
provider.Register("testsection", &ts)
|
||||
}
|
||||
|
||||
// Command is an end-point...
|
||||
func (ts *testsection) Command(w http.ResponseWriter, r *http.Request) {}
|
||||
|
||||
var didRefresh bool
|
||||
|
||||
// Refresh existing data, returning data in the format of the target system
|
||||
func (ts *testsection) Refresh(meta, data string) string {
|
||||
ts.didRefresh = true
|
||||
didRefresh = true
|
||||
return ""
|
||||
}
|
||||
|
||||
|
@ -40,8 +42,8 @@ func (*testsection) Render(meta, data string) string {
|
|||
return "testsection " + data
|
||||
}
|
||||
|
||||
func (*testsection) Meta() TypeMeta {
|
||||
section := TypeMeta{}
|
||||
func (*testsection) Meta() provider.TypeMeta {
|
||||
section := provider.TypeMeta{}
|
||||
|
||||
section.ID = "TestGUID"
|
||||
section.Title = "TestSection"
|
||||
|
@ -52,13 +54,13 @@ func (*testsection) Meta() TypeMeta {
|
|||
}
|
||||
|
||||
func TestSection(t *testing.T) {
|
||||
if _, ok := Refresh("testsection", "", ""); !ok {
|
||||
if _, ok := provider.Refresh("testsection", "", ""); !ok {
|
||||
t.Error("did not find 'testsection' smart section (1)")
|
||||
}
|
||||
if !ts.didRefresh {
|
||||
if !didRefresh {
|
||||
t.Error("did not run the test Refresh method")
|
||||
}
|
||||
out, ok := Render("testsection", "meta", "dingbat")
|
||||
out, ok := provider.Render("testsection", "meta", "dingbat")
|
||||
if !ok {
|
||||
t.Error("did not find 'testsection' smart section (2)")
|
||||
}
|
||||
|
@ -66,7 +68,7 @@ func TestSection(t *testing.T) {
|
|||
t.Error("wrong output from Render")
|
||||
}
|
||||
|
||||
sects := GetSectionMeta()
|
||||
sects := provider.GetSectionMeta()
|
||||
for _, v := range sects {
|
||||
if v.Title == "TestSection" {
|
||||
return
|
||||
|
|
|
@ -14,6 +14,7 @@ package utility
|
|||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"strings"
|
||||
"unicode/utf8"
|
||||
|
||||
|
@ -27,7 +28,7 @@ import (
|
|||
type HTML string
|
||||
|
||||
// write out the textual element of the html node, if present, then iterate through the child nodes.
|
||||
func writeText(n *html.Node, b *bytes.Buffer, isTest bool) {
|
||||
func writeText(n *html.Node, b io.Writer, isTest bool) {
|
||||
if !excluded(n) {
|
||||
switch n.Type {
|
||||
case html.TextNode:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue